更新时间:2022-06-14 03:04:48
对此还有一个答案.我发布了一个单独的答案,因为它更像是一个精确"的答案.尝试解决方案而不是可能的解决方案列表:
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"}}