Basically 2 Types of Directives are available...
- Built in Directives
- Custom Directives
- ng-app
- ng-init
- ng-model
- ng-change
- ng-hide
- ng-value
- ng-disabled
- ng-repeat
Custom Directives
In addition to the Built In Angular JS directives, We can create our own directives with the help of the
.directive function.
Invoking a directives can by done in 4 ways
- Element name (E)
- Attribute (A)
- Class (C)
- Comment (M)
For better understanding look into the sample code below
<!DOCTYPE html>
<head>
<title></title>
<script src="angular.min.js"></script>
<script>
var app =
angular.module("MyNgApp", []);
app.directive("directiveAttributeTest", function () {
return {
restrict: "A",
link: function
() {
alert("Attribute Test");
}
}
});
app.directive("directiveElementTest", function () {
return {
restrict: "E",
link: function
() {
alert("Element Test");
}
}
});
app.directive("directiveCommentTest", function () {
return {
restrict: "M",
link: function
() {
alert("Comment test ");
}
}
});
app.directive("directiveClassTest", function () {
return {
restrict: "C",
link: function
() {
alert("Class
Test");
}
}
});
</script>
</head>
<body ng-app="MyNgApp">
<div directive-attribute-test></div>
<div class="directive-class-test"></div>
<directive-element-test></directive-element-test>
<!-- directive: directive-comment-test -->
</body>
</html>
No comments:
Post a Comment