← BYTES
AngularJS·Starter·Ref: 5.1.11

How does ng-if differ from ng-show in terms of the DOM?

Have a question about this video? Mention reference 5.1.11 when you contact us.

a.They behave identically
b.ng-if is purely a styling directive with no logic
c.ng-if only works inside forms
d.ng-if actually adds or removes the element (and its scope) from the DOM entirely based on the expression, while ng-show only toggles CSS visibility
ng-if creates/destroys the element (and a new child scope) each time the expression's truthiness changes, whereas ng-show/ng-hide leave the element in the DOM at all times and merely hide it visually -- this matters for initialization cost and for any directives that rely on being compiled fresh.

Find this on YouTube & Instagram

Every BYTES video is tagged with its reference number and topic — search any of these on YouTube or Instagram to find this one:

#BYTES#BYTES5111#AngularJS