相关疑难解决方法(0)

Angularjs if-then-else表达式中的构造

我可以以某种方式在angularjs表达式中使用if-then-else构造(三元运算符),例如我有函数$ scope.isExists(item)必须返回bool值.我想要这样的东西,

<div ng-repeater="item in items">
    <div>{{item.description}}</div>
    <div>{{isExists(item) ? 'available' : 'oh no, you don't have it'}}</div>
</div>
Run Code Online (Sandbox Code Playgroud)

我知道我可以使用返回字符串的函数,我很有兴趣在表达式中使用if-then-else构造.谢谢.

javascript if-statement ternary-operator angularjs angularjs-ng-repeat

108
推荐指数
3
解决办法
19万
查看次数