Wednesday, 24 June 2015

angular directive


directive


scope: 

true, then system will create an isolate scope for it.

Controller: 

Can be a function, like this: function($scope){}

Can be a controller name string , like this "xxx"

Link function  (injection is not supported yet.)

link: function (scope, el, attrs){
    el.append("<h1>SB</h1>").        //you can get the dom element here by "el" and change it .
                                                         // el is jqlite.
         //attrs are all attributes on the dom element.
}


link: {
      pre:function(){}
     post: function(){}
}



life cycle:  (calling directive functions.)

    pre link
    controller
    post link

If:

<directive-1>
    <directive-2></directive-2>
</directive-1>

it will do:


    pre link -1
    pre link -2    controller-1
    controller-2    post link-2
    post link-1


compile

rarely use.







No comments:

Post a comment