Thursday, December 18, 2014

JS: angular 1.3+ one-time-bindings with ng-if

So as I warned the readers, there will be javascript-related stuff in my blogs, propably as time goes by, more and more.

Now getting the angular 1.3+ one time bindings to work in my app, I had to do a lot of work. I just discovered today that my ng-ifs act weirdly with the bindings. Basically what I have often in my code, is something like this:
ng-if=" myUserData_shiftChanges[thisDay.dbFormat][siteIndex][groupIndex] && myUserData_basicData.id === userIndex"
Now that works fine, when we don't involve one time bindings, but, when it changes to this:
::( myUserData_shiftChanges[thisDay.dbFormat][siteIndex][groupIndex] && myUserData_basicData.id === userIndex )
It will create a watcher for this, eventhough it shouldn't.

I tracked the issue to angular handling ng-ifs that don't return something solid like true or false. I basically changed my code to one-line IFs, like so:
::( myUserData_shiftChanges[thisDay.dbFormat][siteIndex][groupIndex] && myUserData_basicData.id === userIndex ) ? true : false
And now they work fine again.

No comments:

Post a Comment