0
我使用ng-repeat
实例化了一个小部件。初始创建工作正常,但之后停止更新。下面是index.html
的摘录:当使用ng-repeat时删除列表项时未被删除的Transcluded元素
<div>
<x-node ng-repeat="node in nodes"></x-node>
</div>
谐音/ node.html:
<div>{{node.name}}</div>
而且指令:
angular.module('directive', []).directive('node', function() {
return {
restrict: 'E',
scope: true,
templateUrl: 'partials/node.html',
replace: true,
compile: function(tElement, tAttrs, transclude) {
return {
post: function(scope, iElement, iAttrs) {
scope.$on('$destroy', function(event) {
console.log('destroying');
});
}
};
}
};
});
如果我修改这样的控制台节点列表:
var e = angular.element($0);
var s = e.scope();
s.nodes.splice(1,1);
s.$apply()
...然后$destroy
回调运行,但渲染的元素不会改变。我的指令中有什么遗漏吗?
演示:Plunker
不应该'template'是'templateUrl'? – 2013-04-23 03:48:20
@JosephSilber啊是的,的确如此。谢谢,我在问题中解决了这个问题。 – z0r 2013-04-23 03:55:31
@阿伦,感谢Plunker的演示!我注意到如果模板被包含在指令中而没有使用templateUrl,它似乎可以工作... – z0r 2013-04-23 04:40:45