当用户登陆页面时,API 中的对象包含一个 bool 值,如下所示:
"Globals": [
{
"key": "HasDebitCard",
"value": "True"
}
]
因此,如果“值”为“true”或“false”,它(链接)将导航到正确的位置。代码如下:
<div class="toolTile col-md-3">
<a ng-href="{{ ppt.Globals.value.True ? '#/claimEnter' : '#/clearSwipe' }}">
<img src="ppt/assets/toolIcons/submiticon.svg" >
<p>Submit a Claim for Reimbursement</p>
</a>
</div>
但是,当用户单击此链接时,无论“值”是否设置为“True”或“False”,它始终会转到同一位置“clearSwipe”。在 DOM 中,它显示为导航到同一位置:
<a ng-href="#/claimEnter" href="#/claimEnter">
不确定为什么它应该以一种或另一种方式呈现。我在这里做错了什么?
非常感谢。
最佳答案
现在,ppt.Globals.value.True
将始终返回 undefined
。当您想要检查 ppt.Globals.value
是否等于 True 时,请使用以下语法 ppt.Globals.value == 'True'
<div class="toolTile col-md-3">
<a ng-href="{{ ppt.Globals[0].value == 'True' ? '#/claimEnter' : '#/clearSwipe' }}">
<img src="ppt/assets/toolIcons/submiticon.svg" >
<p>Submit a Claim for Reimbursement</p>
</a>
</div>
关于javascript - 用于导航用户的 Angular 三元运算符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32639000/