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

ng.getContext

如果在嵌入式视图中(例如 *ngIf*ngFor),则检索元素所属的嵌入式视图的上下文。否则,检索其视图中拥有该元素的组件的实例(在这种情况下,其结果与调用 getOwningComponent 相同)。

If inside an embedded view (e.g. *ngIf or *ngFor), retrieves the context of the embedded view that the element is part of. Otherwise retrieves the instance of the component whose view owns the element (in this case, the result is the same as calling getOwningComponent).

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

要获取外围组件实例的元素。

Element for which to get the surrounding component instance.

返回值

元素外围组件的实例;如果元素不在任何组件内,则为 null。

T | null: Instance of the component that is around the element or null if the element isn't inside any component.