这个例子适用于AngularJS 1.1.5(它会将它附加到div中),但是1.2.5不能(它会留下没有附加的html内容).
https://egghead.io/lessons/angularjs-transclusion-basics
app.directive("panel", function() {
return {
restrict: "E",
transclude: true,
template: '<div class="panel" ng-transclude>This is a panel component</div>'
}
})
Run Code Online (Sandbox Code Playgroud)
AngularJS 1.1.5:http://plnkr.co/edit/BLe56D9YZxSIAiJ31wW0("这是..."按预期显示)AngularJS 1.2.5:http://plnkr.co/edit/h6dUrXXXBOQUtzsJqT4S("这是... ."没有出现)
在1.1.5"transclude:true"按预期工作(文本附加到面板),但在> 1.2.0中没有.
有帮助吗?
小智 5
将指令中的模板更改为:
template: '<div class="panel" >This is a panel component</div><div ng-transclude></div>'
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1223 次 |
| 最近记录: |