[英]js .append() Angular Directive not compiling
Simplified I have the following problem, I want to append to a div using the jquery function .append(), an Angular directive and it won't work. 简化后,我遇到以下问题,我想使用jQuery函数.append()(一个Angular指令)附加到div,它将无法正常工作。 I've created a jsfiddle to make my point. 我创建了一个jsfiddle来说明我的观点。 http://jsfiddle.net/H26eg/2/ http://jsfiddle.net/H26eg/2/
Do you have any idea why isn`t it working and what should i do? 您知道为什么它不起作用,我该怎么办?
I think it is related to this http://docs.angularjs.org/api/ng.$compile
but can`t figure it out.. 我认为它与此http://docs.angularjs.org/api/ng.$compile
有关,但无法弄清楚。
Thanks a lot ! 非常感谢 !
EDIT: I've managed to do the above using two directive, calling one directive from the other like this: http://jsfiddle.net/H26eg/6/ . 编辑:我已经设法使用两个指令来执行上述操作,从另一个像这样调用一个指令: http : //jsfiddle.net/H26eg/6/ 。 The problem is if instead of regular template:"html_text"
in anpr directive I use templateUrl: "path_to_html_file"
again it won't compile the directive. 问题是如果在anpr指令中代替常规template:"html_text"
,而我再次使用templateUrl: "path_to_html_file"
,它将无法编译该指令。 Can somebody please tell me how to compile the templateUrl directive ? 有人可以告诉我如何编译templateUrl指令吗?
Finaly done it using a controller function: 最后使用控制器功能完成此操作:
<div data-ng-controller="SetupController">
<input data-ng-click="addAnpr('tabs_1','anpr')" type="button" value="Add"/>
<div id="tabs_1">
</div>
</div>
.. ..
app.controller('SetupController', function ($scope, $compile) {
$scope.addAnpr = function (tab,drctv) {
var el = $compile('<'+drctv+'/>')($scope);
$('#'+tab).append(el);
}
});
app.directive('anpr', function () {
return{
restrict: 'E',
templateUrl: 'app/partials/SETUP/anprTab.html'
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.