Angularjs ngSwitch有静态节点吗?

时间:2013-08-23 19:50:43

标签: javascript angularjs angularjs-directive

如何在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>

jsfiddle

switch元素呈现为模板的最后一个子元素。任何想法,如果有更好的方法?

1 个答案:

答案 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