ComponentRef

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> 只读

The component type.

方法

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

abstract destroy(): void
      
      abstract destroy(): void
    
参数

没有参数。

返回值

void

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

abstract onDestroy(callback: Function): void
      
      abstract onDestroy(callback: Function): void
    
参数
callback Function

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

返回值

void