angularjs选择有条件的选项?

时间:2014-07-23 06:39:11

标签: javascript angularjs

我制作并且angularJS选择菜单工作正常:

<select 
    name="s1" 
    id="s1" 
    multiple="multiple" 
    data-native-menu="false" 
    data-role="none"
    ng-model="userlistSelect" 
    ng-options="u.userId as u.firstName for u in member.getList()">
</select>

我的控制器是:

$scope.member = items;  

如何实现以下目标:如果firstName不可用,则显示emailID

1 个答案:

答案 0 :(得分:1)

当firstName为falsy时,您可以更改ng-options以显示emailID ...

ng-options="u.userId as (u.firstName || u.emailID) for u in member.getList()"

Live Demo - Fiddle