在 Angular.js 模板中,我需要测试值是否未定义或为空......我不知道如何执行此操作,因为ng-switch-when
测试字符串中的表达式。我需要使用ng-switch
因为这是一个 if else 条件。有任何想法吗?
<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 允许表达式,您可以使用占位符,如下所示:
<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 空字符串 https://stackoverflow.com/questions/12434284/ng-switch-on-empty-string
您通常在控制器中执行此操作(请参阅链接线程中的答案#1)。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)