The ng-if is a directive in AngularJS which is used to remove the HTML element if the value of the expression or variable is false, unlike ng-hide which just hides the HTML element from the DOM.
<element angular_directive=expression> Contents... </element>
There are few other options which behave like ng-if. There is no difference among them in functionality wise.
Note: The best practice is to use ng-if only.
The reason behind why these options come into the picture is that in AngularJS we refer to the directive using camel case (example:ngIf) but when we use it in HTML since HTML is case insensitive we use a dash-delimited form (example:ng-if) or other delimiters as mentioned in the list above. So the AngularJS normalizes (It means it converts the delimiter form into camelcase.) the element’s tag and figures out to which directive does the element belong.
Example 1: This example uses “data-ng-if” directive.
Example 2: This example uses “ng-if” directive.
- How to use *ngIf else in AngularJS ?
- How to use ngIf without an extra element in Angular2?
- Directives in JSP
- AngularJS | Directives
- Structural Directives in Angular
- Angular 7 | Directives
- Difference between node.js require and ES6 import and export
- Difference Between DOS and Windows
- Difference Between Apache Kafka and Apache Flume
- Difference between Bootstrap and AngularJS
- Difference Between HTML and ASP
- Difference between ASP and ASP.NET
- Difference between Preemptive Priority based and Non-preemptive Priority based CPU scheduling algorithms
- What is the Difference between Website and Web Portal
- Difference between Web Scraping and Web Crawling
- Difference between try-catch and if-else statements in PHP
- Difference between Algorithm, Pseudocode and Program
- Difference between Dropbox and OneDrive
- Difference between Applets and Servlets
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.