Analysis of four basic forms of instruction in Angularjs _angularjs

Source: Internet
Author: User
Tags commit


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.


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.