0

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

 <div ng-switch on="list.type">
   <ul ng-switch-when="unorder">
    <li ng-repeat="item in items">
            {{ item.text }}
    </li>
   </ul ng-switch-when="unorder">
    <ol ng-switch-when="order">
        <li ng-repeat="item in items">
            {{ item.text }}
        </li>
    </ol ng-switch-when="order">
 </div>
4

2 回答 2

1

我认为这是更优雅的方式,使用 css 而不是使用自定义指令来完成一些非常简单的事情

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;
}

您可以在此处查看实时示例

于 2015-11-11T18:36:13.013 回答
0
<div>
  <list content="list.type">
    <li ng-repeat="item in items">
      {{ item.text }}
    </li>
  </list>
</div>

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

于 2015-11-11T18:35:58.763 回答