【发布时间】:2014-04-25 05:11:48
【问题描述】:
为什么replace=true 或replace=false 对下面的代码没有任何影响?
为什么replace=false时不显示“一些现有内容”?
或者更谦虚一点,您能否解释一下指令中的replace=true/false 功能是什么以及如何使用它?
示例
JS/角度:
<script>
angular.module('scopes', [])
.controller('Ctrl', function($scope) {
$scope.title = "hello";
})
.directive('myDir', function() {
return {
restrict: 'E',
replace: true,
template: '<div>{{title}}</div>'
};
});
</script>
HTML:
<div ng-controller="Ctrl">
<my-dir><h3>some existing content</h3></my-dir>
</div>
在 Plunker 中查看:
【问题讨论】:
标签: angularjs angularjs-directive