Cookies concent notice

This site uses cookies from Google to deliver its services and to analyze traffic.
Learn more
Skip to main content
This site is no longer updated.Head to Angular.devHome
/

This is the archived documentation for Angular v17. Please visit angular.dev to see this page for the current version of Angular.

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 setInput(name: string, value: unknown): void
abstract destroy(): void
abstract onDestroy(callback: Function): void }

Properties

Property Description
abstract location: ElementRef Read-Only

The host or anchor element for this component instance.

abstract injector: Injector Read-Only

The dependency injector for this component instance.

abstract instance: C Read-Only

This component instance.

abstract hostView: ViewRef Read-Only

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

abstract changeDetectorRef: ChangeDetectorRef Read-Only

The change detector for this component instance.

abstract componentType: Type<any> Read-Only

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

Methods

Updates a specified input name to a new value. Using this method will properly mark for check component using the OnPush change detection strategy. It will also assure that the OnChanges lifecycle hook runs when a dynamically created component is change-detected.

      
      abstract setInput(name: string, value: unknown): void
    
Parameters
name string

The name of an input.

value unknown

The new value of an input.

Returns

void

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

      
      abstract destroy(): void
    
Parameters

There are no parameters.

Returns

void

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

      
      abstract onDestroy(callback: Function): void
    
Parameters
callback Function

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

Returns

void