为什么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>
Run Code Online (Sandbox Code Playgroud)
HTML:
<div ng-controller="Ctrl">
<my-dir><h3>some existing content</h3></my-dir>
</div>
Run Code Online (Sandbox Code Playgroud)
在Plunker中看到它: