Introduction
In this blog, we will learn about some of the most important in-built directives in AngularJS and see some examples on each directive. Let's start!
Directive in Angular
Directives are used to extend the HTML and most of the in-built directives in AngularJS start with the ng- prefix. AngularJS allows us to create our own elements as well! This makes directives the most powerful and the most celebrated feature of the framework.
Some of the most important in-built directives are listed below.
- ng-app
- ng-model
- ng-bind
- ng-init
- ng-repeat
ng-app
This directive is used to start an AngularJS application and it is used to load various modules in the Angular application. Normally, only one ng-app directive can be used in your HTML document.
Example
In this example, the ng-app directive is in the <div> tag and it is calculating the sum of two numbers using {{}} interpolation symbol.
- <html>
- <head>
- <title></title>
- <script src="angular.min.js"></script>
- </head>
- <body>
- <div ng-app=""><!-- Starting the angularjs application -->
- <p>Sum = {{10+10}}</p>
- </div>
- </body>
- </html>
ng-model
The ng-model directive is used to bind the value of HTML control into application data.
Example
In this example, the ng-model directive creates a model variable "name" and shows "name" variable using interpolation symbol {{name}}.
- <html>
- <head>
- <title>ng-model</title>
- <script src="angular.min.js"></script>
- </head>
- <body>
- <div ng-app="">
- <p>Enter your Name: <input type="text" ng-model="name"></p>
- <p>Your Name is {{name}} </p>
- </div>
- </body>
- </html>
ng-bind
This directive is used to bind the HTML tags into application data.
Example
In this example, the ng-model directive creates a model variable "name" and the ng-bind use the "name" model to be displayed in the HTML <span> tag whenever the user enters input in the text box.

Join the conversation! Your thoughts help the community grow.