ng.getDirectives
检索与给定 DOM 元素关联的指令实例。不包括组件实例。
Retrieves directive instances associated with a given DOM node. Does not include component instances.
ng.getDirectives(node: Node): {}[]
参数
node | Node | 要为其获取指令的 DOM 元素。 DOM node for which to get the directives. |
返回值
与元素关联的指令数组。
{}[]
: Array of directives associated with the node.
使用说明
给定以下 DOM 结构:
Given the following DOM structure:
<my-app>
<button my-button></button>
<my-comp></my-comp>
</my-app>
在 <button>
上调用 getDirectives
将返回一个数组,该数组带有与 DOM 元素关联 MyButton
Calling getDirectives
on <button>
will return an array with an instance of the MyButton
directive that is associated with the DOM node.
在 <my-comp>
上调用 getDirectives
将返回一个空数组。
Calling getDirectives
on <my-comp>
will return an empty array.