首页 > Web开发 > 详细

Angular JS 中 指令详解

时间:2018-03-05 00:32:58      阅读:264      评论:0      收藏:0      [点我收藏+]

Angular JS的强大功能就在于其可以自定义很多指令,现在就指令做一下详细的剖析。

一个Angular js 指令(directive)的生命周期 开始于$compile方法 结束于$link方法。

angular.module(‘myApp‘, [])
.directive(‘myDirective‘, function() {
  return {
    restrict: String,
    priority: Number,
    terminal: Boolean,
    template: String or Template Function:
      function(tElement, tAttrs) (...},
    templateUrl: String,
    replace: Boolean or String,
    scope: Boolean or Object,
    transclude: Boolean,
    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) { ... }
        }
        // 或者
        return function postLink(...) { ... }

      }
   };
});

 

Angular JS 中 指令详解

原文:https://www.cnblogs.com/Pikzas/p/8506899.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!