自定义指令

自定义指令 :用 directive 

               angular.module("myApp",[]).directive("proList",fn)

                通过添加 restrict 属性,值可以为 "ACEM", 来设置指令只能通过怎样的方式来调用: 默认值为AE

                                        A:作为属性使用;(<span pro-list></span>)

              E:作为元素名使用;  sppro-list

              C:作为class类名使用;

              M:作为注释使用(已渐渐褪去很少使用)

                 template:指令的模块

            replace:如果值为true只显示指令里面的内容   为false html里面写的标签也存在

<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<script src="../angular-1.5.5/angular.min.js"></script>

</head>
<body ng-app="myApp">
<my-div></my-div> <span>E</span>
<p class="my-div"></p> <span>C</span>
<p my-div=""></p> A
<!-- directive: my-div -->


</body>
<script>
var app=angular.module("myApp",[]);
app.directive("myDiv",function(){
return {
restrict:'C',
template:"<div>我是自定义指令</div>"
}
})
</script>
原文地址:https://www.cnblogs.com/yaomengli/p/6845658.html