AngularJS Directives :
Its directives are expanded HTML features with the affix ng-
<div ng-app=”” ng-init=”product=’Bread'”>
<p>Product Name: <input type=”text” ng-model=”product”></p>
<p>Product Name is: {{ product }}</p>
</div>
The ng-app directive additionally describes that the <div> component is the proprietor of the angular application.
We can bind the data using ng-model directive.
In the below example we are going to bind two text fields using ng-model directives:
<div data-ng-app=”” data-ng-init=”firstname=Angular;lastname=Js”>
First Name: <input type=”text” ng-model=”firstname”>
Last Name <input type=”text” ng-model=”lastname”>
<p><b>Name:</b> {{firstname + ” ” + lastname}}</p>
</div>
<div ng-app=”” ng-init=”productdetail=[
{name:’Bread’,price:’40’},
{name:’Cheese’,price:’100′}]”>
<ul>
<li ng-repeat=”product in productdetail”>
{{ product.name + ‘, ‘ + product.price }}
</li>
</ul>
</div>
For binding the data of HTML controls like:-input, select, textarea to application data.
The ng-model directive can likewise:
<body ng-app=”directive1″>
<a-new-directive></a-new-directive>
<script>
var dir = angular.module(“directrive1”, []);
dir.directive(“aNewDirective”, function() {
return {
template : “<p>Created New Directive</p>”
};
});
</script>
</body>
Directives can be invoked by using:
Element name
<a-new-directive></a-new-directive>
Attribute
<p a-new-directive></p>
Class
<p class=”a-new-directive”></p>
Comment
<!—New Directive: a-new-directive –>
If you want to restrict your directive usage. Like,If you want that your directives will be invoked by some of the methods.
For restricting the directives use restrict property.
var dir = angular.module(“directive1”, []);
dir.directive(“aNewDirective “, function() {
return {
restrict : “E”,
template : “<p>Created New Directive</p>”
};
});
The legal restrict values are:
Utilizing value CM, It implies that both class and remark can summon the order.
After summarizing all the AngularJs directives that are listed above. We can say that directives are attribute on a DOM element that tell AngularJS to join a specified actions to that DOM element or even convert the DOM element and its children. it broadens the HTML.
Refer more AngularJs Directive.
Source:- http://www.w3schools.com