javascriptangularjsperformancedirectivejqlite

angular.element().hide() versus ngIf


Angular gives access to some jquery functions here

I'm just wondering if there is any difference in performance between .hide() and using the ngIf directive?

Added clarification that came from comments

I understand the difference between ngIf and ngShow, but I'm wondering about the performant differences between using the ng directives versus calling angular.element() and chaining it with .hide()


Solution

  • the .hide() method is equivalent to .css( "display", "none" ), while ng-if remove the element from the dom. This is the major difference.

    jqlite .hide() acts the same way as ng-show / ng-hide directives

    The .ng-hide CSS class is predefined in AngularJS and sets the display style to none (using an !important flag).

    https://docs.angularjs.org/api/ng/directive/ngShow