【问题标题】:Angularjs1.x Directive Prelink/Postlink/link function difference?Angularjs1.x Directive Prelink/Postlink/link 功能区别?
【发布时间】:2017-05-29 06:44:52
【问题描述】:

我在很多教程中试图理解angularjs指令的prelink/postlink函数,但无法识别正常的链接函数,是相当于pre link还是post link函数。

(1) 

link : function(scope element, attrs) {

} 

(2)

pre : function(scope element, attrs) {

} 

(3)

post : function(scope element, attrs) {

} 

"(1) 是否等于 (2) || (1) 是否等于 (3)" ??

【问题讨论】:

    标签: angularjs angularjs-directive


    【解决方案1】:

    看了这么多博客和教程,终于得到了我的答案here

    对于 AngularJs,link 函数是一个 post-link 函数。所以一般我们可以通过两种方式编写post-link函数:

    (1) 使用具有 post 方法链接的对象字面量表示法:

      link:{ post:function(scope,elem,attr)
        {
          // .....
        }
       }
    

    (2) 只需设置链接方式。

    link: function(scope,elem,attr){
           // ...      
          }
    

    【讨论】:

      猜你喜欢
      • 2018-11-13
      • 2013-10-28
      • 1970-01-01
      • 1970-01-01
      • 2021-07-13
      • 2019-01-28
      • 1970-01-01
      • 2018-01-22
      • 2019-10-07
      相关资源
      最近更新 更多