2017-05-29 107 views
-2

我想了解许多教程中的angularjs指令prelink/postlink函数,但无法确定正常链接函数是否等同于前链接或后链接函数。Angularjs1.x指令预链接/后链接/链接功能区别?

(1) 

link : function(scope element, attrs) { 

} 

(2) 

pre : function(scope element, attrs) { 

} 

(3) 

post : function(scope element, attrs) { 

} 

“是(1)等于(2)||(1)等于(3)” ??

回答

0

经历了那么多的博客和教程会后,终于得到了我的答案here

对于AngularJs的链接功能是一个链接后功能。所以一般我们可以通过两种方式编写链接后功能:

(1)利用具有交方法链接对象的文字符号:

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

(2)简单地设置链接的方法。

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