在本文件:http://docs.angularjs.org/guide/directive,它说,有是一个指令配置replace
:如何使用`replace`指令定义?
模板 - 与HTML的内容替换当前元素。替换过程将所有属性/类从旧元素迁移到新元素。有关更多信息,请参阅下面的创建组件部分。
JavaScript代码
app.directive('myd1', function(){
return {
template: '<span>directive template1</span>',
replace: true
}
});
app.directive('myd2', function(){
return {
template: '<span>directive template2</span>',
replace: false
}
});
HTML代码
<div myd1>
original content should be replaced
</div>
<div myd2>
original content should NOT be replaced
</div>
但最后的页面看起来像:
directive template1
directive template2
看起来replace
不起作用。我错过了什么吗?
现场演示:http://plnkr.co/edit/rGIgmjO81X2UxJohL4HM?p=preview
什么transclude: '元素'。它使用ng-transclude时似乎与replace一样:'true'。 – CMCDragonkai 2014-02-26 12:06:21
是replace:false,就像没有使用replace一样? – Neil 2014-03-19 13:25:47
@ Neil是的。将它关闭与'false'相同# – checketts 2014-03-19 15:33:57