Directives are the normal HTML Syntax. AngularJS allows you to extend existing HTML syntax with new attributes called as Directives. AngularJS comes with set of inbuilt Directives and all the Directives has individual behaviors.
All the Directives are starts with the prefix of “ng-”. Also AngularJS allows the developer to create custom Directives with custom behaviors.
To Know More about all the Directives and other Topics, Please Visit AngularJS Complete Topics.
Here are the list of Top 10 Directives in AngularJS,
- ng-hide / ng-show
This directive is used for auto bootstrap an AngularJS Application. It’s also called as root element of an AngularJS. This directive almost placed on <html> or <body>. Without this directive we can’t implement AngularJS in our application.
We can use only one ng-app directive per HTML Document. If you use multiple ng-app directives, the 1st one will be auto bootstrap the application. You can pass application name as a parameter of ng-app .
ng-model Directive is used for Bind AngularJS application data into Input elements like text, password, select, check box, radio, etc.,
Here the elements are All types of Input elements.
This directive used for bind angularjs application data into the views. We can bind the application data through a variable and whenever the variable value gets change, automatically the view update the value and vice versa.
ng-bind as a Attribute
ng-bind as a Class
<element class=”ng-bind: expression”></element>
Bind the values by using an expression
ng-click directive just like a onClick event. ng-click allows you to call a angularjs function when an element clicked. We can use onClick and ng-click together in a same element. 1st onClick will trigger after that ng-click event trigger.
ng-controller directive is used for controller angularjs Application data. Also it allows you to attach your application controller to the view. The controller scopes are based on the element scopes. This ng-controller directive allows nested that we can use a controller within a controller.
6.ng-hide / ng-show :
ng-hide / ng-show directives are used to show are hide the views (HTML Template) based on the Boolean values. Every ng-hide, ng-show has a expression which having Boolean values.
If the above expression is true then the element will be hide and if it’s false the element will be show.
If the above expression is true then the element will be show and if it’s false the element will be hide.
This directive works like ng-hide but the different is ng-hide just hide the element based on the truthy value and ng-if remove the element based on the truthy value. If the ng-if expression value is false means it will remove from the document and when the value gets true it will again attach the element into the document.
ng-directive is used for include external html file into the application. The including html file should be child node of the specified element.
ng-include directive have a expression and the expression have the value of external file name.
ng-include as an element
ng-include as an attribute
<element ng-include=”filename” ></element>
ng-repeat directive repeat the specific html element until the number of times of an array elements. It clones the html elements at every iteration.
The collection should be an array or object.
<element ng-repeat=”variableName in Array/Object Name”></element>
ng-submit directive like onSubmit event. It will trigger the function while your form submit. This directive attached on form and it will work only when the form doesn’t contain action.
Here is the complete collection of AngularJS, Please Visit AngularJS from Scratch.