AngularJS Directives17 Mar 2025 | 5 min read 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 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. AngularJS directives ExampleLet's take an example to use all the above discussed directives: Test it NowAngularJS Directives ListAnglarJS directives are used to add functionality to your application. You can also add your own directives for your applications. Following is a list of AngularJS directives:
How to add directivesSee this example: Test it NowNext TopicAngularJS ng-app Directive |
We request you to subscribe our newsletter for upcoming updates.