填写这份《一分钟调查》,帮我们(开发组)做得更好!去填写Home

ng.getComponent

Retrieves the component instance associated with a given DOM element.

ng.getComponent<T>(element: Element): T | null
      
      ng.getComponent<T>(element: Element): T | null
    
参数
element Element

DOM element from which the component should be retrieved.

返回值

T | null: Component instance associated with the element or null if there is no component associated with it.

使用说明

Given the following DOM structure:

<my-app> <div> <child-comp></child-comp> </div> </my-app>
      
      <my-app>
  <div>
    <child-comp></child-comp>
  </div>
</my-app>
    

Calling getComponent on <child-comp> will return the instance of ChildComponent associated with this DOM element.

Calling the function on <my-app> will return the MyApp instance.