2015年9月12日

Directive 的使用

restrict 的取值可以有三种:

  • A 用于元素的 Attribute,这是默认值

  • E 用于元素的名称

  • C 用于 CSS 中的 class

我们这样定义指令。

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>

查看元素的结果如下:

Javascript 常用获取时间函数

React程序

生成一个基本标签。

Last updated

Was this helpful?