神刀安全网

AngularJS From Beginning: Directive – Part Four

compile: function compile(tElement, tAttrs, transclude) {   return  {   pre: function preLink(scope, iElement, iAttrs, controller) { ... },   post: function postLink(scope, iElement, iAttrs, controller) { ... }   }   }   

And for link, it is:

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

Notice that one difference here is that the link function gets access to a scope but compile does not. This is because during the compile phase, the scope doesn’t exist yet. You do, however, have the ability to return link functions from the compile function. These link functions do have access to the scope. Notice also that both compile and link receive a reference to their DOM element and the list of attributes for that element. The difference here is that the compile function receives the template element and attributes from the template, and thus gets the prefix. The link function receives them from the view instances created from the template, and thus gets the prefix.

转载本站任何文章请注明:转载至神刀安全网,谢谢神刀安全网 » AngularJS From Beginning: Directive – Part Four

分享到:更多 ()

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址