Angular.js ng-switch-测试值是否为空或未定义 [英] Angular.js ng-switch ---testing if value is empty or undefined
本文介绍了Angular.js ng-switch-测试值是否为空或未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在Angular.js模板中,我需要测试值是否未定义或为空....由于ng-switch-when
测试字符串中的表达式,因此我不确定如何执行此操作.我需要使用ng-switch
,因为这是一个if else条件.有什么想法吗?
In Angular.js templating, I need to test if a value is undefined or empty.... I am not sure how to do this since ng-switch-when
tests for expressions in strings. I needed to use ng-switch
because it's a if else condition. Any ideas?
<div ng-switch="vipLabel">
<div ng-switch-when="vipLabel.toString()">
<h1>Getting infomration...one sec</h1>
</div>
<div ng-switch-default>
<h3>Do you wish to unbind {{node.label}} from {{ vipLabel }}?</h3>
</div>
</div>
推荐答案
ng-switch允许表达式,可以使用占位符,例如:
ng-switch allows expressions, you can use placeholder, as such:
<div ng-switch="selection || '_undefined_'" >
<span ng-switch-when="_undefined_">I am set to zero or undefined?!</span>
<span ng-switch-default>This string is not empty</span>
</div>
有关更多信息:在空字符串上进行ng-switch
您通常在控制器内执行此操作(请参见链接线程中的答案1).
You usually do it within controller(see answer#1 in linked thread).
这篇关于Angular.js ng-switch-测试值是否为空或未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文