0

I'm working on an angular app, and I'm trying to set up a repeater with ng-switch.

The code I have so far looks like this:

<ion-content>
    <ion-list>
        <ion-item menu-close ng-repeat="room in rooms" ng-switch="room.id" href="#/app/details/{{room.id}}" id="room-list-entry-{{room.id}}" class="item item-icon-right">

           <!--Template for id 0-->
           <div ng-switch-when="0" class="myHouse">
                testing template id 0
            </div>

            <!--Template for all the other rooms-->
            <div ng-switch-default class="rooms">
                testing template all the others
            </div>
          </ion-item>
     </ion-list>

ng-switch works fine, as I can see the right text, the problem I've got now is that I need to change the url, to something like this:

<a href="{{if room id == 0}}#/app/house{{else}}#/app/details/{{room.id}}{{/if}}"> 

This is the bit that i'm stuck with, as i don't really know if it is even possible to do something this way with ng-if.

I know that the easies way would be to move the href inside the ng-switch-when, but the problem is that if I move it, than the list printed by the ionic framework doesn't render properly anymore...

How can I change the link according to the id using angular in a proper way?

Thanks

Nick
  • 13,493
  • 8
  • 51
  • 98

1 Answers1

1

Use ng-href:

<a ng-href="{{room.id == 0 ? '#/app/house' : '#/app/details/' + room.id}}">

http://jsfiddle.net/sm4xpe58/

Boris Parnikel
  • 863
  • 1
  • 7
  • 15