Get one-time binding to work for ng-if

This question has been asked before, but I can't get that solution working, so I'm wondering if there's something different in my specifics.

The code is really, really simple:

<h1 ng-if=" !== undefined">update {{}}</h1>

As written, this snippet works fine. If is set, tag appears.

However, if I try to make the one-time binding work, that is:

<h1 ng-if=" !== undefined">update {{}}</h1>

The tag doesn't appear at all. I've tried variations:

<h1 ng-if="::( !== undefined)">update {{}}</h1>

Still nope. It's such a frustratingly simple thing. Hell, the code seems to work in a jsfiddle, but I can't get it working for my particular app. Is there a setting somewhere? Some random bit of trivia I need to change?

Is there I'm using angular 1.5.7, if that matters.


<h1 ng-if=" !== undefined">update {{}}</h1>

That is, setting the {{}} ultimately gives me the result I'm looking for, but at the cost of a additional, useless watcher, right?

Further edit on my edit: this isn't a great solution for a number of reasons.


My problem stems from the fact that waits on an API call and therefore misses the first $watch digest (I think). So instead of "one-time" as defined by angular, is there a way to have ng-if do its thing directly after is set the first time and then quit?



Well, In here you're checking one-time data binding value with undefined and since it is one-time data binding this condition will always be false.

modify your ng-if and make it more simpler

<h1 ng-if="">update {{}}</h1>

Please find working plunker :

This will work!



Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.