我有一个简单的AngularJS directive with a templateUrl。该指令用于工具提示。
Reading the angular docs, there doesn't seem to be any way of making a directive delay rendering。我错过了什么吗?
// Tooltip directive
return function(){
return {
templateUrl: 'someTemplate.html',
replace: false, // Append our tooltip, rather than replace the element's contents.
link: function (scope, element, attrs) {
$element.on({
mouseenter: function () {
// Would like to render, and set up bindings, here (my question)
},
mouseleave: function () {
// Destroy rendered element here (simple stuff, not my question)
}
});
}
}
}
答案 0 :(得分:1)
我相信你需要注入$compile
服务才能在你的回调中做这样的事情:
templateMarkup = '<p> {{ property }} </p>';
$compile(templateMarkup)(scope);
我没有仔细考虑将这些内容放入您的代码中,但请告诉我这是否有用。