0

Any better way to write this? I just dont want to repeat the inner content of the list twice.

 <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>
andresmijares
  • 3,658
  • 4
  • 34
  • 40

2 Answers2

1

I think this is more elegant way by using css instead of using custom-directive for something quite simple

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

Live example you can see here

Dvir
  • 3,287
  • 1
  • 21
  • 33
0
<div>
  <list content="list.type">
    <li ng-repeat="item in items">
      {{ item.text }}
    </li>
  </list>
</div>

With a data binding you can change the list directive template to <ul ng-transclude>or <ol ng-transclude>

iScor
  • 95
  • 4