This article illustrates the four basic forms of instruction in Angularjs. Share to everyone for your reference, specific as follows:
In the four basic forms of instruction,
Note the use of annotation-type instruction M is <!--directive: Directive name--> Note that both the test must have a space to normally identify
All instructions can be combined, do not write restrict, will default to a property directive to support IE8 browser generally best to set the directive as a property
<!doctype html>
<html ng-app="myapp">
<head>
<meta charset="utf-8"/>
</head>
<body>
<elementtag>E</elementtag>
<div attr>A</div>
<div class="classnamw">C</div>
<! -- note that space must be added on both sides of the comment variable, otherwise the instruction will not be executed correctly -- >
<!-- directive:commit -->
<div></div>
<script src="./js/angular.min.js"></script>
<script>
var app = angular.module('myapp',[]);
app.directive('elementtag',function(){
Return {
Restrict: "e", / / element instruction
link:function(scope,element,attrs){
console.log("this is a element");
}
}
}
.directive('attr',function(){
Return {
Restrict: "a", / / attribute instruction
link:function(scope,element,attrs){
console.log("this is a attribute");
}
}
}
.directive('classnamw',function(){
Return {
Restrict: "C", / / class instruction
link:function(scope,element,attrs){
console.log("this is a class");
}
}
}
.directive('commit',function(){
Return {
Restrict: "m", / / comment instruction
link:function(scope,element,attrs){
console.log("this is a commit");
}
}
};
</script>
</html>
I hope this article will help you with ANGULARJS programming.