我试图弄清楚如何用角度绑定工具提示的内容。我有一个看起来像这样的指令:
的script.js
var myApp = angular.module('myApp', []);
myApp.directive('initToolbar', function(){
return {
restrict: 'A',
link: function(scope, element, attrs)
{
$(element).qtip({
content: {
ajax:
{
url: 'button.html'
}
},
position: {
my: 'bottom left',
at: 'bottom middle',
target: $(element)
},
hide: {
fixed : true,
delay : 1000
}
});
}
}
});
它使用qTip2插件 从这里
我的index.html看起来像这样(请注意,在实际文件中我已将所有源代码包含在头部中,我只是不粘贴它以避免混乱):
<body>
<div initToolbar>
<p>
Hover over me. Hover over me. Hover over me.
</p>
</div>
</body>
和
button.html
<div ng-controller="myController">
<button ng-click="someFunction()">Click me</button>
</div>
正如您在指令代码中看到的那样。 button.html被加载到工具提示中,但这会阻止角度正常运行 - 当button.html加载到弹出窗口时,ng-click不起作用。那是因为角度不知道它。
我也知道button.html是有效的,因为只需添加
<ng-include src="'button.html'">
到index.html工作正常(即点击按钮执行someFunction())
所以我的问题是:
如何将工具提示的实际内容与角度绑定?如果不是内容,有没有办法绑定工具提示,所以有角度知道它? 我熟悉$ scope。$ apply()但我不太清楚如何在这里使用它。