91-9990449935 0120-4256464 |
AngularJS DirectivesAngularJS 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 directiveng-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. ng-init directiveng-init directive initializes an AngularJS Application data. It defines the initial values for an AngularJS application. In following example, we'll initialize an array of countries. We're using JSON syntax to define array of countries. ng-model directive:ng-model directive defines the model/variable to be used in AngularJS Application. In following example, we've defined a model named "name". ng-repeat directiveng-repeat directive repeats html elements for each item in a collection. In following example, we've iterated over array of countries. |