AngularJS Directives

AngularJS facilitates you to extend HTML with new attributes. These attributes are called directives.

There is a set of built-in directive in AngularJS which offers functionality to your applications. You can also define your own directives.

Directives are special attributes starting with ng- prefix. Following are the most common directives:

  • ng-app: This directive starts an AngularJS Application.
  • ng-init: This directive initializes application data.
  • ng-model: This directive defines the model that is variable to be used in AngularJS.
  • ng-repeat: This directive repeats html elements for each item in a collection.

# ng-app directive

ng-app directive defines the root element. It starts an AngularJS Application and automatically initializes or bootstraps the application when web page containing AngularJS Application is loaded. It is also used to load various AngularJS modules in AngularJS Application.

See this example:

In following example, we've defined a default AngularJS application using ng-app attribute of a div element.