angular指令

require

引用其他controller

var app = angular.modeule('myapp',[]);

app.directive('common',function(){
    return {
    ...
    controller: function($scope){
        this.method1 = function(){
        };
        this.method2 = function(){
        };
    },
    ...
    }
});

app.directive('d1',function(){
    return {
    ...
    require: '?^common',
    link: function(scope,elem,attrs,common){
        scope.method1 = common.method1;
        ..
        },
    ...
    }
});

app.directive('d2',function(){
    return {
    ...
    require: '?^common',
    link: function(scope,elem,attrs,common){
        scope.method1 = common.method1;
        ..
        },
    ...
    }
});

 

compile

运行在创建dom和scope之前,只执行一次,可以修改dom, ng-repeat 多个dom在compile阶段生成。

 

pre-link

在compile执行之后,子指令的post-link执行之前

 

post-link

执行时,子指令的pre-link和post-link都已经执行完成,可以安全的写业务逻辑

 

posted @ 2015-06-23 00:02  fannet  阅读(163)  评论(0编辑  收藏  举报