在 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 on empty string
您通常在 Controller 中执行此操作(请参阅链接线程中的答案#1)。
关于angularjs - Angular.js ng-switch ---测试值是否为空或未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25453689/