我有一种情况,当用户点击一个链接,我想自定义元素插入到DOM例如插入指令动态和编译
//user clicks
$scope.click = function() {
var el = $compile("<my-directive></my-directive>")($scope);
$element.after(el);
};
的我的指令....指令具有HTML模板..比方说(template1.html)
<p>My Template for my-directive</p>
{{SomeProperty}}
我的指导性的定义如下
module.directive('myDirective', ['$compile', function ($compile) {
return {
restrict: 'E',
replace: true,
templateUrl: '/template1.html',
scope: true
};
}]);
如果我们假设myDirective中的范围在运行此代码后实际上具有SomeProperty的值,那么确实将my-directive插入到DOM中并由模板替换 - template1.html,但{{SomeProperty}}尚未替换为所有!我该怎么做呢??
更多细节
嗯,你可以看看我的plunkr? http://plnkr.co/edit/5Qnv6i8jhyRwMEWtRQO7?p=preview – Paul 2014-09-25 05:01:31