填寫這份《一分鐘調查》,幫我們(開發組)做得更好!去填寫Home

ComponentRef

表示由 ComponentFactory 建立的元件。提供對元件實例和相關物件的訪問,並提供銷燬實例的方法。

Represents a component created by a ComponentFactory. Provides access to the component instance and related objects, and provides the means of destroying the instance.

      
      abstract class ComponentRef<C> {
  abstract location: ElementRef
  abstract injector: Injector
  abstract instance: C
  abstract hostView: ViewRef
  abstract changeDetectorRef: ChangeDetectorRef
  abstract componentType: Type<any>
  abstract destroy(): void
  abstract onDestroy(callback: Function): void
}
    

屬性

屬性說明
abstract location: ElementRef唯讀

此元件實例的宿主或錨點元素

The host or anchor element for this component instance.

abstract injector: Injector唯讀

此元件實例的依賴項注入器

The dependency injector for this component instance.

abstract instance: C唯讀

該元件實例。

This component instance.

abstract hostView: ViewRef唯讀

範本為此元件實例定義的宿主檢視

The host view defined by the template for this component instance.

abstract changeDetectorRef: ChangeDetectorRef唯讀

此元件實例的變更檢測器。

The change detector for this component instance.

abstract componentType: Type<any>唯讀

此元件的型別(由 ComponentFactory 類別建立)。

The type of this component (as created by a ComponentFactory class).

方法

銷燬元件實例以及與其關聯的所有資料結構。

Destroys the component instance and all of the data structures associated with it.

      
      abstract destroy(): void
    
引數

沒有引數。

返回值

void

一個生命週期鉤子,為元件提供其他由開發人員定義的清理功能。

A lifecycle hook that provides additional developer-defined cleanup functionality for the component.

      
      abstract onDestroy(callback: Function): void
    
引數
callback Function

一個處理器函式,用於清理與此元件關聯的由開發人員定義的資料。在呼叫 destroy() 方法時呼叫。

A handler function that cleans up developer-defined data associated with this component. Called when the destroy() method is invoked.

返回值

void