AngularJS : HTML 编译器是如何安排编译顺序的? [英] AngularJS : How does the HTML compiler arrange the order for compiling?

查看:28
本文介绍了AngularJS : HTML 编译器是如何安排编译顺序的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当一个页面上的多个元素有多个指令时,Angular 的 HTML 编译器是如何安排编译顺序的?

When there are multiple directives across multiple elements on a page, how does Angular's HTML compiler arrange the order for compiling?

假设我有以下标记,其中 alpha、beta 和 gamma 是自定义的 Angular 指令,

Say I have the following markups, where alpha, beta, and gamma are custom Angular directives,

<html ng-app>
  <alpha><beta></beta></alpha>
  <gamma></gamma>
</html>

编译器处理它们的顺序是什么?是 alpha => gamma => beta 吗?还是 alpha => beta => gamma?

What's the order the compiler would work on them? Is it alpha => gamma => beta? Or is it alpha => beta => gamma?

为了让事情更复杂一点,考虑 alpha 指令的模板有另一个自定义指令,称为 foo.foo 什么时候会被编译?在所有上述指令都被编译之后?还是在 alpha 编译之后?

To complicate things a little bit more, consider alpha directive's template has another custom directive, called foo. When would foo get compiled? After all of the above directives get compiled? Or right after alpha is compiled?

推荐答案

我在 AngularJS 邮件列表中提出了同样的问题,Peter Bacon Darwin 用 jsfiddle 给出了一个很好的答案,用于演示.链接

I asked the same question in the AngularJS mailing list and Peter Bacon Darwin gave a great answer with a jsfiddle for demonstration. Link

这篇关于AngularJS : HTML 编译器是如何安排编译顺序的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆