我正在尝试使用此代码获取工具提示并使用此代码:
http://embed.plnkr.co/v6bqqe/index.html
我的ngtable看起来像这样:
<table ng-table="tableParams" class="table">
<tr ng-repeat="user in $data">
<td data-title="'Name'">{{user.name}}</td>
<td data-title="'Age'">{{user.age}}</td>
<td data-title="'Comments'">
<div my-qtip qtip-title="{{user.name}}" qtip-content="{{user.comment}}">
hover here
</div>
</td>
</tr>
</table>
因此尝试将usercomment属性显示为工具提示。问题是当将鼠标悬停在评论栏上时如何在表格中显示这个内容?
答案 0 :(得分:1)
你需要稍作改动:
http://plnkr.co/edit/eP5fiFrWvcoVveYWAQzr?p=preview
var text = attrs['qtipContent'];
var title = attrs['qtipTitle'];
以下是整个指令:
app.directive("myQtip", function () {
return function (scope, element, attrs) {
/******* This is what's different from myQtip *********/
var text = attrs['qtipContent'];
var title = attrs['qtipTitle'];
/******************************************************/
scope.qtipSkin = (attrs.skin ? "qtip-" + attrs.skin : "qtip-dark");
element.qtip({
content: {
text: text,
title: title
},
style: {
classes: scope.qtipSkin + " qtip-rounded qtip-shadow "
},
show: {
event: 'click mouseover',
solo: true
},
hide: {
event: (scope.closeButton == true ? "false" : "click mouseleave"),
delay: 300,
fixed: (($(this).hover || attrs.fixed) ? true : false), //prevent the tooltip from hiding when set to true
leave: false
},
position: {
viewport: $(window),// Keep it on-screen at all times if possible
target: (attrs.target ? attrs.target :"event"),
my: "bottom center",
at: "top center"
}
});
scope.$on("$destroy", function () {
$(element).qtip('destroy', true); // Immediately destroy all tooltips belonging to the selected elements
});
$('[my-qtip]').css("display", "inline-block");
}
});