我创建了一个带有链接函数的指令,其中包含带有 ng-include
的元素。但是这个带有 ng-include
的元素不起作用。
有谁知道为什么不起作用?
app.directive('helloWorld', function () {
return {
link: function (scope, elem, attrs) {
var div = document.createElement('div');
div.setAttribute('ng-include', "page2.html'");
elem.append(div);
}
};
});
最佳答案
您添加了没有编译它,编译后它可以工作。
app.directive('helloWorld',['$compile', function ($compile) {
return {
link: function (scope, elem, attrs) {
var div = document.createElement('div');
div.setAttribute('ng-include', "'page2.html'");
elem.append(div);
$compile(div)(scope);
}
};
}])
这里是link
关于javascript - AngularJS ng-include 在指令链接中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38630517/