如何在ngSwitch中有一些公共节点?
<div ng-controller="MyCtrl">
<div ng-repeat="widget in widgets" ng-switch="" on="widget.foo">
<h1>Test</h1>
<p ng-switch-when="bar">Lorem ipsum</p>
<small ng-switch-when="baz">Lorem ipsum</small>
<footer>common footer</footer>
</div>
</div>
switch元素呈现为模板的最后一个子元素。任何想法,如果有更好的方法?
答案 0 :(得分:2)
试试这个:
<div ng-controller="MyCtrl">
<div ng-repeat="widget in widgets">
<h1>Test</h1>
<div ng-switch on="widget.foo">
<p ng-switch-when="bar">Lorem ipsum</p>
<small ng-switch-when="baz">Lorem ipsum</small>
</div>
<footer>common footer</footer>
</div>
</div>
jsFiddle here。