Ad

Angular Performance With Ng-if="!!someVar" Vs Ng-if="someVar"

- 1 answer

Hi I was just wondering if one can gain better performance using ng-if="!!someVar" where someVar is an object that either is defined or undefined instead of ng-if="someVar". Both clearly work in Angular JS I was wondering what is easier for javascript and angular to evaluate?

In summary, which is the best way to write the ng-if directive when testing for the presence of an object in the current $scope/context.

ng-if="!!someVar or ng-if="someVar"

Ad

Answer

You may see performance gains if you were using purely JavaScript, but since you are already using The AngularJS ng-ifDirective, I hardly think you need to worry about a performance difference between ng-if="!!someVar" and ng-if="someVar" to see if that object exists.

I'm sure you are also aware that ng-if is preferred over ng-show, so it's not as though ng-if is not recommended.

Some resources:

Ad
source: stackoverflow.com
Ad