Directives are markers on a DOM elements (HTML Tags, attribute, comment or CSS class) that tell compiler of AngularJS ($compile) to attach a specified behavior on these DOM elements or even transform them and its childrens.
In short, Directives are markers in the HTML tag that tells Angular to run or reference JavaScript code. Following are list of most of the directives in AngualarJS
AngularJs directives generally starts with ng however we can also prefix it with “data” like “data-ng-app”. So instead of writing ng-app, we can write data-ng-app.
We shall learn about these directives one by one in their separate posts.
Generally directives are written dash delimited as an attribute to the HTML element, however it can also be written in following ways
<script>
var app = angular.module("app", [])
.controller("NormalizeController", function ($scope) {
$scope.name = "Sheo Narayan, TechFunda";
});
</script>
<div ng-app="app" ng-controller="NormalizeController">
<p ng-bind="name"></p>
<p ng:bind="name"></p>
<p ng_bind="name"></p>
<p data-ng-bind="name"></p>
<p x-ng-bind="name"></p>
<hr />
<p class="ng-bind: name;"></p>
</div>
See the highlighted code snippet, where the ng-bind directive is written in following ways
All these directives will have the same output.
Output
Views: 20721 | Post Order: 6