ComponentRef

Represents an instance of a Component created via a ComponentFactory.

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

说明

ComponentRef provides access to the Component Instance as well other objects related to this Component Instance and allows you to destroy the Component Instance via the destroy method.

属性

属性名类型说明
location只读

Location of the Host Element of this Component Instance.

injector只读

The injector on which the component instance exists.

instance只读

The instance of the Component.

hostView只读

The ViewRefof the Host View of this Component instance.

changeDetectorRef只读

The ChangeDetectorRefof the Component instance.

componentType只读

The component type.

方法

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

abstract destroy(): void

参数

没有参数。

返回值

void

Allows to register a callback that will be called when the component is destroyed.

abstract onDestroy(callback: Function): void

参数

callback

Type: Function.

返回值

void