Executable example:

http://jsbin.com/secuz/5/edit?html,js,output

http://jsbin.com/secuz/5/edit?html,js,output

Details

The above failure contradicts my assumption about in what order Angular directives are processed. I would expect that outer directives get run first, then execution propagates inwards.

上述失败与我对Angular指令处理顺序的假设相矛盾。我希望外部指令先运行,然后执行向内传播。

Am I correct to think that this out-of order evaluation is due to ng-if having higher priority than ng-show? And if so, shouldn't priorities only be taken into account if two directives are on the same element?

我是否认为这种无序评估是由于ng-如果比ng-show具有更高的优先级?如果是这样,如果两个指令在同一个元素上,那么不应该只考虑优先级吗?

Main question

How can I make sure execution always goes from outside in? Do I need to give the same priority to all the directives I use?

我怎样才能确保执行始终从外部进行?我是否需要对我使用的所有指令给予相同的优先权?

Edit:

Tried 2 additional scenarios:

尝试了另外2个场景:

  • If both are ng-ifs, then the propagation happens from outside-in, just as expected:
  • 如果两者都是ng-ifs,则传播从外向内发生,正如预期的那样:

[[ '1 if', true ], [ '2 if', true ], [ '1 if', true ], [ '2 if', true ]]

[['1 if',true],['2 if',true],['1 if',true],['2 if',true]]

  • However, two ng-shows exhibit a counter-intuitive behaviour:
  • 然而,两个ng-shows表现出反直觉的行为:

[[ '2 show', true ], [ '1 show', true ], [ '2 show', true ], [ '1 show', true ]]

[['2 show',true],['1 show',true],['2 show',true],['1 show',true]]

1 个解决方案

#1


2

Compilation involves these three call-back-bindable steps:

编译涉及这三个可回调绑定的步骤:

  • compile
  • pre-link
  • 前链路
  • post-link
  • 后链接

More here.

更多这里。

I am not sure where ng-show and ng-if do their behavior, but I bet you could find out.

我不确定ng-show和ng-if在哪里做他们的行为,但我打赌你可以找到。

If ng-show and ng-if set up the behavior you're testing in the post-link, that actually executes in reverse order, climbing up from the lowest element and back out, so this would explain your finding.

如果ng-show和ng-if设置你在后链接中测试的行为,它实际上以相反的顺序执行,从最低元素爬升并退出,这样就可以解释你的发现。

更多相关文章

  1. 将对象值传递给指令而不是任何其他数据变量
  2. Angularjs指令ng-hide在单元格模板中不对网格数据的更改进行绑定
  3. 当开始使用数据-*时,无法识别AngularJS指令
  4. $ postLink的角度组件/指令运行得太早
  5. element.replaceWith在自定义指令的链接中仅在第一次调用时工作
  6. Mac下MySQL-python安装及EnvironmentError: mysql_config not fo
  7. Python 2.6.2中的ElementTree处理指令支持?
  8. 通过指令“ps -l”查看进程信息
  9. 常见压缩格式的区别,及 Linux 下的压缩相关指令

随机推荐

  1. React native Android(安卓)命令 打包apk
  2. 51. (android开发)线性布局、相对布局、
  3. Android札记
  4. 关于“Only the original thread that cr
  5. Android换肤机制
  6. Android点击事件的四种写法
  7. Android编程: 环境搭建、基本知识
  8. 杂七杂八2
  9. Android去除标题栏及自定义title栏
  10. android资源配置文件