AngularJS transclude不起作用

时间:2014-01-01 08:25:16

标签: angularjs

这个例子适用于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>'
    }
})

AngularJS 1.1.5:http://plnkr.co/edit/BLe56D9YZxSIAiJ31wW0(“这是......”按预期显示)AngularJS 1.2.5:http://plnkr.co/edit/h6dUrXXXBOQUtzsJqT4S(“这是......”没有出现)

在1.1.5中,“transclude:true”按预期工作(文本附加到面板),但在&gt;中1.2.0没有。

任何帮助?

2 个答案:

答案 0 :(得分:5)

将指令中的模板更改为:

template: '<div class="panel" >This is a panel component</div><div ng-transclude></div>'

答案 1 :(得分:0)

事实上,现在可以捕获确切的行为:

template: '<div class="panel"> This is a panel component <div ng-transclude></div></div> '

即。如果您想要面板中的按钮,面板文本也会显示在面板中。

顺便说一下,我不知道为什么。

相关问题