ng-switch放置元素

时间:2015-11-11 18:27:56

标签: angularjs angularjs-ng-switch

有更好的方式来写这个吗?我只是不想两次重复列表的内部内容。

Event

2 个答案:

答案 0 :(得分:1)

我认为通过使用css而不是使用custom-directive来实现非常简单的

,这是更优雅的方式

<强> HTML

<ol ng-class="{'no-style' : list.type === 'unorder'}">
    <li ng-repeat="item in items">
        {{ item.text }}
    </li>
</ol>

<强> CSS

ol.no-style {
    list-style-type: none;
}

实例您可以看到here

答案 1 :(得分:0)

<div>
  <list content="list.type">
    <li ng-repeat="item in items">
      {{ item.text }}
    </li>
  </list>
</div>

使用数据绑定,您可以将列表指令模板更改为 <ul ng-transclude><ol ng-transclude>