0 votes
1 view
in Web Technology by (47.8k points)

I'm trying to understand the difference between ng-if and ng-show/ng-hide, but they look the same to me.

Is there a difference that I should keep in mind choosing to use one or the other?

1 Answer

0 votes
by (107k points)

The difference between ng-if and ng-show/ng-hide is as follows:-

What is ngIf:-

It removes or recreates a portion of the DOM tree based on an expression. If the ngIf expression evaluates to a false value then the element is removed from the DOM, otherwise, a clone of the element is reinserted into the DOM.

See the code below:-

<div ng-if="1"></div> 

<div ng-if="0"></div>

What is ngShow:-

It shows or hides the given HTML element based on the expression provided to the ngShow attribute. The element is shown or hidden by removing or adding the ng-hide CSS class onto the element. Also, the ng-hide CSS class is predefined in AngularJS and sets the display style to none.

See the code below:-

<div ng-show="1"></div>

<div ng-show="0" class="ng-hide"></div>

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...