angularJs 指令的理解

指令:

  可以把指令理解成为特定的DOM 上运行的函数,指令扩展了这个元素的功能;

例如:ng-click--在DOM元素上绑定了一个click事件的监听,并在监听到事件时运行angular表达式

自定义事件:

  directive(name,function(){return{...}});

以下是自定义指令的全部配置属相

myModule.directive('newDirective', function factory(injectables) {

        return {

            restrict: string,//指令的使用方式,包括标签,属性,类,注释

            priority: number,//指令执行的优先级

            template: string,//指令使用的模板,用HTML字符串的形式表示

            templateUrl: string,//从指定的url地址加载模板

            replace: bool,//是否用模板替换当前元素,若为false,则append在当前元素上

            transclude: bool,//是否将当前元素的内容转移到模板中

            scope: bool or object,//指定指令的作用域

            controller: function controllerConstructor($scope, $element, $attrs, $transclude){...},//定义与其他指令进行交互的接口函数

            require: string,//指定需要依赖的其他指令

            link: function postLink(scope, iElement, iAttrs) {...},//以编程的方式操作DOM,包括添加监听器等

            compile: function compile(tElement, tAttrs, transclude){

                return: {

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

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

                }

            }

        };

});
原文地址:https://www.cnblogs.com/web-Rain/p/6070214.html