首页 > 解决方案 > 如何在工具提示中显示 html ng-repeat

问题描述

我正在使用 angularjs,所以我在我的应用程序中添加了一个指令。

app.directive('tooltip', function () {
    return {
        restrict: 'A',
        link: function (scope, element, attrs) {
            $(element)
                .attr('title', scope.$eval(attrs.tooltip))
                .tooltip({ placement: "right" });
        }
    }
})

我想显示下面的 html 或类似的东西,我只想在tooltip

<ol>
    <li ng-repeat='dt in detail.SelectedCustomers'>{{dt.name}}</li>
</ol>

下面是我所在的桌子tooltip

<tr ng-repeat="detail in mainCtrl.lineDetails">
    <td><a href="#" data-toggle="tooltip" data-placement="right" data-html="true" tooltip="detail.SelectedCustomers"><i class="fa fa-eye fa-lg" aria-hidden="true"></i></a></td>
</tr>

标签: angularjshtml-tableangularjs-ng-repeattooltip

解决方案


我做了一个小提琴来告诉你你能做些什么

.directive("myTooltip", [ function(){
return{
scope: {
customers:'=myTooltip'
},
link:function(scope, el){
var toDisplay = '';
for(var i = 0; i < scope.customers.length; i++){
toDisplay += scope.customers[i].name+'\n';
}

el.attr('title', toDisplay);

推荐阅读