andresmijares
andresmijares

Reputation: 3744

ng-switch to place elements

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>

Upvotes: 0

Views: 238

Answers (2)

Dvir
Dvir

Reputation: 3339

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

Upvotes: 1

iScor
iScor

Reputation: 95

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

Upvotes: 0

Related Questions