3

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?

1
  • I just tried, and ng-if="::!vm.user.loggedIn" works for me: jsfiddle.net/858tk3nn Commented Nov 18, 2015 at 20:19

2 Answers 2

5

Try:

<div ng-if="::(!vm.user.loggedIn)"></div>

Demo Plunkr:

http://plnkr.co/edit/ZcV3yxTiERtPiPlMJb2L?p=preview

Sign up to request clarification or add additional context in comments.

Comments

2

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 completely 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.

1 Comment

1+ Because ng-if="::!vm.user.loggedIn" should work - jsfiddle.net/858tk3nn

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.