发表于: 2019-12-26 22:21:11

1 1192


今天完成的事:

看指令。


明天的计划:

写复盘设计,继续刚指令


遇到的困难:

指令里的配置项还是有点搞不明白。


今天的收获:

除了 AngularJS 内置的63个指令外,我们还可以创建自定义指令。你可以使用 .directive 函数来添加自定义的指令。要调用自定义指令,HTML 元素上需要添加自定义指令名。使用驼峰法来命名一个指令, runoobDirective, 但在使用它时需要以 - 分割, runoob-directive,自定义指令的参数如下:

 return {

    restrict:String,                

    priority:Number,

    terminal:Boolean,

    template:String or Template Function,

    templateUrl:String or Template Function,

    replace:Boolean or String,

    transclude:Boolean,

    scope:Boolean or Object,

    controller:String or function(scope, element, attrs, transclude, otherInjectables) { ... },

    controllerAs:String,

    require:String,

    link: function(scope, iElement, iAttrs) { ... },

    compile:function(tElement, tAttrs, transclude) {

        return {

            pre: function(scope, iElement, iAttrs, controller) { ... },

            post: function(scope, iElement, iAttrs, controller) { ... }


restrict是申明标识符在模板中作为元素,属性,类,注释或组合,如何使用。有四个值:E、A、C、M。

2、priority: Number

priority是指令执行优先级。若在单个DOM上有多个指令,则优先级高的先执行;

设置指令的优先级算是不常用的

3、template: String or Function

(1)、字符串

template是指令链接DOM模板

4、emplateUrl: String

templateUrl是指定一个字符串式的内嵌模板,如果你指定了模板是一个URL,那么是不会使用的。

templateUrl :配置文件需要显示在页面上的东西,如:需要显示一个另一个页面则输入路径 连接dom模版的路径 表达形式:String

template:配置需要读取的东西因为没有URL所以读取的一般是标签或者文字,连接dom模版的   表达形式:String


我写demo的时候也就用到这几个。。而且priority 还不知道作用到底如何。。。



返回列表 返回列表
评论

    分享到