0

我正在开发一个有角度的应用程序,我正在尝试使用 ng-switch 设置一个中继器。

到目前为止,我的代码如下所示:

<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 工作正常,因为我可以看到正确的文本,我现在遇到的问题是我需要将 url 更改为如下所示:

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

这是我坚持的一点,因为我真的不知道是否可以用 ng-if 以这种方式做某事。

我知道最简单的方法是将href移动到ng-switch-when中,但问题是如果我移动它,离子框架打印的列表将不再正确呈现......

如何以正确的方式使用 angular 根据 id 更改链接?

谢谢

4

1 回答 1

1

使用 ng-href:

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

http://jsfiddle.net/sm4xpe58/

于 2016-03-01T15:02:45.483 回答