Angular指令——函数执行的正确顺序

Angular Directive - Correct order of execution of functions

本文关键字:顺序 执行 指令 函数 Angular      更新时间:2023-09-26

根据以下两个博客感到有点困惑:

Eric W Green - Toptalhttps://www.toptal.com/angular-js/angular-js-demystifying-directives

执行顺序

Compile -> Controller -> PreLink -> PostLink

二世。 JsonMorehttp://jasonmore.net/angular-js-directives-difference-controller-link/

执行顺序

Controller -> Compile -> PreLink -> PostLink

复杂问题的答案控制器 &link在这里给出——如果在编译之前需要在控制器中使用代码,或者在编译后运行的link if代码中写入。

但是,blog 1说两者都在编译后运行。请建议哪一个是正确的?

这个概念实际上是令人困惑的,但是如果你理解了实际的流程,它将始终保持清晰。

实际的执行顺序是…编译->控制器->链接前->链接后

要想进一步了解,就把这篇文章看一遍吧,它确实对我有帮助。

希望对你有帮助。

欢呼