admin管理员组文章数量:1429100
I know the syntax for one-way binding inside ng-if looks like this:
<div ng-if="::vm.user.loggedIn"></div>
(from here)
But what's the syntax if I want to use one-way binding with the not operator? I've tried something like
<div ng-if="!::vm.user.loggedIn"></div>
or
<div ng-if="::!vm.user.loggedIn"></div>
No luck. Any ideas?
I know the syntax for one-way binding inside ng-if looks like this:
<div ng-if="::vm.user.loggedIn"></div>
(from here)
But what's the syntax if I want to use one-way binding with the not operator? I've tried something like
<div ng-if="!::vm.user.loggedIn"></div>
or
<div ng-if="::!vm.user.loggedIn"></div>
No luck. Any ideas?
Share Improve this question edited Nov 18, 2015 at 20:08 DJ. 6,7841 gold badge35 silver badges49 bronze badges asked Nov 18, 2015 at 20:06 Paul ErdosPaul Erdos 1,3752 gold badges23 silver badges49 bronze badges 1-
I just tried, and
ng-if="::!vm.user.loggedIn"
works for me: jsfiddle/858tk3nn – Josh Crozier Commented Nov 18, 2015 at 20:19
2 Answers
Reset to default 5Try:
<div ng-if="::(!vm.user.loggedIn)"></div>
Demo Plunkr:
http://plnkr.co/edit/ZcV3yxTiERtPiPlMJb2L?p=preview
It's not one-way binding, but one time binding that you are talking about. One time bindings only use the first value, and then never update.
However, <div ng-if="::!vm.user.loggedIn"></div>
is pletely valid and should work correctly. See this plunker for example: http://plnkr.co/edit/o1va21WuuAykFRTBOGRT?p=preview
The internal code angular uses doesn't do anything special to the expression, aside from stripping off the two colons at the start and changing a oneTime
boolean. My guess is that you have some other logic (probably asynchronous) that determines vm.user.loggedIn
and the 1 time binding uses the initial value, then does not update, or there is some other error preventing the code from working.
本文标签: javascriptSyntax for conditional oneway binding in ngif expression in Angular JSStack Overflow
版权声明:本文标题:javascript - Syntax for conditional one-way binding in ng-if expression in Angular JS - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745498298a2660910.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论