您的位置:首页 > Web前端 > AngularJS

angularjs学习之七(angularjs中指令的四种基本形式)

2015-07-08 09:18 681 查看
指令的四种基本形式中,

注意注释型指令 M 的使用方法是 <!-- directive:指令名称 --> 注意左右俩测必须有空格才会正常识别

所有指令是可以相互组合 的,不写restrict ,将会默认为A属性 指令

要支持IE8 浏览器 一般最好将指令设置为属性

<!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>
<!-- 注意注释变量两侧必须加上空格 否则不会正确执行这个指令 -->
<!-- directive:commit -->
<div></div>

<script src="./js/angular.min.js"></script>
<script>
var app = angular.module('myapp',[]);

app.directive('elementtag',function(){
return {
restrict:"E", //元素指令
link:function(scope,element,attrs){
console.log("this is a element");
}
};
})
.directive('attr',function(){
return {
restrict:"A", //属性指令
link:function(scope,element,attrs){
console.log("this is a attribute");
}
};
})
.directive('classnamw',function(){
return {
restrict:"C", //class 指令
link:function(scope,element,attrs){
console.log("this is a class");
}
};
})
.directive('commit',function(){
return {
restrict:"M", //注释指令
link:function(scope,element,attrs){
console.log("this is a commit");
}
};
});

</script>
</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: