且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

angular.js 中的内联条件

更新时间:2022-06-14 03:04:48

2Toad's answer below 就是你'重新找!给那个东西点赞

如果您使用的是 Angular <= 1.1.4,那么这个答案就可以:

对此还有一个答案.我发布了一个单独的答案,因为它更像是一个精确"的答案.尝试解决方案而不是可能的解决方案列表:

2Toad's answer below is what you're looking for! Upvote that thing

If you're using Angular <= 1.1.4 then this answer will do:

One more answer for this. I'm posting a separate answer, because it's more of an "exact" attempt at a solution than a list of possible solutions:

这是一个过滤器,它将执行立即如果"(又名 iif):

Here's a filter that will do an "immediate if" (aka iif):

app.filter('iif', function () {
   return function(input, trueValue, falseValue) {
        return input ? trueValue : falseValue;
   };
});

并且可以这样使用:

{{foo == "bar" | iif : "it's true" : "no, it's not"}}