填写这份《一分钟调查》,帮我们(开发组)做得更好!去填写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