标签:
restrict 的取值可以有三种:
比如说,我们这样定义指令。
var app = angular.module("app", []) .directive("hello", function () { var option = { restrict: "AEC", template: "Hello, Directive", }; return option; })
由于我们指定了可以用于三种情况下,那么,就可以如下三种形式来使用这个指令
<!-- 元素 -->
<div>
<hello></hello>
</div>
<!-- 属性-->
<div>
<div hello></div>
</div>
<!-- class -->
<div>
<div class="hello"></div>
</div>
输出的结果分别如下:
<!-- 元素 -->
<div>
<hello>Hello, Directive</hello>
</div>
<!-- 属性-->
<div>
<div hello="">Hello, Directive</div>
</div>
<!-- class -->
<div>
<div class="hello">Hello, Directive</div>
</div>
标签:
原文地址:http://www.cnblogs.com/lixuemin/p/4913595.html