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.
Syntax:
html
Output:
Example 2: This example uses "ng-if" directive.
html
Output:

<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.
- ng:if
- ng_if
- x-ng-if
- data-ng-if
<!DOCTYPE html>
<html>
<head>
<title>
What is the difference between ng-if
and data-ng-if directives ?
</title>
<script src=
"https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js">
</script>
</head>
<body ng-app="">
<center>
<h1 style="color:green">
GeeksforGeeks
</h1>
<input ng-model="var1">
<div data-ng-if="var1">
<h3>
This will disappear if the value of
input var1 is set to false and will
appear again when true
</h3>
</div>
</center>
</body>
</html>
Example 2: This example uses "ng-if" directive.
<!DOCTYPE html>
<html>
<head>
<title>
What is the difference between ng-if
and data-ng-if directives ?
</title>
<script src=
"https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js">
</script>
</head>
<body ng-app="">
<center>
<h1 style="color:green">
GeeksforGeeks
</h1>
<input ng-model="var1">
<div ng-if="var1">
<h3>
This will disappear if the value of
input var1 is set to false and will
appear again when true
</h3>
</div>
</center>
</body>
</html>
