Directives In AngularJS

AngularJS comes with a set of these directives built-in, like ngBind, ngModel, and ngClass.
As we create controllers and services we can also create our own directives.
Custom directives are used in AngularJS to extend the functionality of HTML. Custom directives are defined using “directive” function. A custom directive simply replaces the element for which it is activated.

AngularJS provides support to create custom directives for following type of elements.

  • Element directives – Directive activates when a matching element is encountered.
  • Attribute – Directive activates when a matching attribute is encountered.
  • CSS – Directive activates when a matching css style is encountered.
  • Comment – Directive activates when a matching comment is encountered.

Here we can discuss some of the directives:

  • ng-app
    This directive starts an AngularJS Application. It defines the root element.When web page containing AngularJS Application is loaded, it automatically initializes the application.
  • ng-init
    This directive initializes an AngularJS Application data. Can be used to put values to the variables to be used in the application.

  • ng-model
    This directive binds the values of AngularJS application data to HTML input controls.

  • ng-repeat
    ng-repeat directive repeats html elements for each item in a collection.

Leave a Reply

Your email address will not be published. Required fields are marked *