【发布时间】:2014-09-25 03:57:56
【问题描述】:
我有一个场景,当用户点击一个链接时,我想在 DOM 中插入一个自定义元素,例如
//user clicks
$scope.click = function () {
var el = $compile("<my-directive></my-directive>")($scope);
$element.after(el);
};
my-directive.. 指令有一个 html 模板.. 比如说 (template1.html)
<p>My Template for my-directive</p>
{{SomeProperty}}
my-directive 是这样定义的
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
【问题讨论】:
标签: angularjs