What is the difference between ng-if and data-ng-if directives ? Last Updated : 23 Jul, 2019 Comments Improve Suggest changes Like Article Like Report 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: <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 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. html <!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> Output: Example 2: This example uses "ng-if" directive. html <!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> Output: Comment More infoAdvertise with us Next Article What is the difference between ng-if and data-ng-if directives ? S sivapriyatn Follow Improve Article Tags : Web Technologies AngularJS AngularJS-Misc Similar Reads What is the difference between '@' and '=' in directive scope in AngularJS ? AngularJS is a popular JavaScript framework, that provides powerful features for building dynamic web applications. When creating custom directives in AngularJS, you may come across the need to define a scope for your directive. The two most common methods to do this are by using the @ and = symbols 4 min read What is the difference between ng-app and data-ng-app in AngularJS ? In web application development, AngularJS is one of the most favorite dynamic JavaScript frameworks that has HTML through script tags, enabling us to augment the HTML attributes using the directives and facilitating the data binding through the expressions.In this article, we will see the concepts o 5 min read What is the difference between Service Directive and Module in Angular ? Angular is a Typescript framework used to build dynamic and Single-Page Applications. This has a strong focus on modularity and reusability of code which helps in creating complex and maintainable applications. At the core, Angular has 3 fundamental building blocks, i.e., Service, Directive and Modu 6 min read What is the difference between declarations, providers, and import in NgModule? Let us first discuss about these terms: Declarations: Declarations are used to declare components, directives, pipes that belongs to the current module. Everything inside declarations knows each other.Declarations are used to make directives (including components and pipes) from the current module a 2 min read What's the difference between ng-pristine and ng-dirty in AngularJS ? AngularJS supports client-side form validation. AngularJS keeps track of all the form and input fields and it also stores the information about whether anyone has touched or modified the field or not. The two different classes ng-dirty and ng-pristine that are used for form validation, are described 2 min read What is the difference between change and ngModelChange in Angular? change: The change event is fired for <input>, <select>, and <textarea> elements when an alteration to the element's value is committed by the user.The change event is not necessarily fired for each alteration to an element's value. change is a DOM event that is it can trigger chan 2 min read Difference between directives and components In Angular, directives, and components are essential concepts that help to build dynamic and interactive web applications. While they both play significant roles, understanding their differences and use cases is crucial for effective Angular development. DirectivesDirectives in Angular are instructi 4 min read What is the difference between the $parse, $interpolate and $compile services? In AngularJS applications, the $parse, $interpolate and $compile services are the most important components as these services are used for data binding. Here, the $parse is mainly responsible for parsing and evaluating the expressions in the context of the application's scope. The $interpolate handl 6 min read Difference between structural and attribute directives Structural directives manipulate the DOM layout by adding, removing, or replacing elements, while attribute directives modify the appearance or behavior of elements without affecting their structure. Directives in Angular are nothing but the classes that allow us to add and modify the behavior of el 5 min read What is the Difference Between factory and service in AngularJS ? AngularJS is a JavaScript-based framework. It can be used by adding it to an HTML page using a <script> tag. AngularJS helps in extending the HTML attributes with the help of directives and binding of data to the HTML with expressions. In this article, we will explore the differences between t 4 min read Like