![]() |
VOOZH | about |
ng-if directive: The ng-if directive in AngularJS is used to remove or recreate a portion of the HTML element based on an expression. If the expression inside it is false then the element is removed and if it is true then the element is added to the DOM.
Syntax:
<element ng-if="expression"> Contents... </element>Approach:
Note: For more information go to chrome-inspect-element-tool-shortcut.
Code Implementation:
Output:
Before Clicking all buttons: Here, we have three buttons to click and buy respective items.
π ImageIn Inspect window: we can see that ng-if is commented out and a part of the DOM tree as expression evaluated to be False.
π ImageAfter Clicking all buttons: As we have clicked all the buttons and purchased every item, a message is displayed on the screen.
π ImageIn Inspect window: we can see that ng-if is now not commented anymore and now it is a part of the DOM tree as expression evaluated to be True.
π ImageThis gif output shows what all is happening.