javascript - Syntax for conditional one-way binding in ng-if expression in Angular JS - Stack Overflow

I know the syntax for one-way binding inside ng-if looks like this:<div ng-if="::vm.user.logged

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
Add a ment  | 

2 Answers 2

Reset to default 5

Try:

<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条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信