本文介绍了在后角JS指令链路VS pre链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于这里概述:

角JS指令采取两种不同类型的链接功能:

Angular js directives take two different types of link functions:

pre-链接功能
子元素链接之前执行。没有安全做DOM转型,因为编译器链接功能将无法找到正确的元素联系起来。

Pre-linking functionExecuted before the child elements are linked. Not safe to do DOM transformation since the compiler linking function will fail to locate the correct elements for linking.

联邮功能
子元素被链接后执行。它是安全的DOM转型后链接功能。

Post-linking functionExecuted after the child elements are linked. It is safe to do DOM transformation in the post-linking function.

此外,似乎链接的默认密钥如果给一个匿名函数将绑定到 postLink

Additionally, it appears that the default key of link will bind to postLink if given an anonymous function.

当,为什么我会永远想使用pre链接功能?

When and why would I ever want to use a pre link function?

推荐答案

您想使用一个pre连接的唯一情况是,当你需要之前的任何子元素上执行范围上有所preparation编译。

The only time you'd want to use a pre link is when you need to perform some preparation on the scope before any child elements compile.

写电网指令时定义的范围和设置网格对象我的团队已经用它的一些之前任何一个子行和单元格对象编制的,需要它的属性。

My team has used it when writing a grid directive to define the grid object on the scope and setup some of its properties that are needed before any of the child row and cell objects are compiled.

希望帮助!

这篇关于在后角JS指令链路VS pre链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 10:00