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.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745498298a4630294.html
评论列表(0条)