例如,我想显示元素if $scope.test === 'hi"。我该如何实现这一点?
我试过这个:
<div ng-if = " {{test}} == 'hi' ? true : false ">
Show this if $scope.test is equal to 'hi'
</div>示例here似乎不起作用。My fail plunker.
发布于 2015-07-28 02:46:37
你不需要一个三元组,因为ng-if需要一个布尔值。这样就可以了:
<div ng-if = "test == 'hi'">
Show this if $scope.test is equal to 'hi'
</div>如果愿意,您仍然可以使用三元组,只是不需要插入变量:test == 'hi' ? true : false
问题出在你非常老的Angular版本上。看看它在1.3中的应用:http://plnkr.co/edit/cKZkOe1O4EBiIWeirlZ2?p=preview
发布于 2015-07-28 02:46:04
恩。您不能在ng-if中使用{{}}。
<div ng-if = " test == 'hi'">
Show this if $scope.test is equal to 'hi'
</div>以上作品
编辑
这在您的柱塞中失败了,因为ng-if指令是在angular 1.1.5之后提供的,而您正在使用1.0.5。
工作版本
http://plnkr.co/edit/3XHe1Ngw1Ntv5FCTBJwA
发布于 2015-07-28 02:46:43
这里不需要三元表达式,只需使用ng-show即可。
<div ng-show="test"></div>https://stackoverflow.com/questions/31660860
复制相似问题