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.

reflectComponentType

Creates an object that allows to retrieve component metadata.

      
      reflectComponentType<C>(component: Type<C>): ComponentMirror<C> | null
    
Parameters
component Type<C>

Component class reference.

Returns

ComponentMirror<C> | null: An object that allows to retrieve component metadata.

Usage notes

The example below demonstrates how to use the function and how the fields of the returned object map to the component metadata.

      
      @Component({
  standalone: true,
  selector: 'foo-component',
  template: `
    <ng-content></ng-content>
    <ng-content select="content-selector-a"></ng-content>
  `,
})
class FooComponent {
  @Input('inputName') inputPropName: string;
  @Output('outputName') outputPropName = new EventEmitter<void>();
}

const mirror = reflectComponentType(FooComponent);
expect(mirror.type).toBe(FooComponent);
expect(mirror.selector).toBe('foo-component');
expect(mirror.isStandalone).toBe(true);
expect(mirror.inputs).toEqual([{propName: 'inputName', templateName: 'inputPropName'}]);
expect(mirror.outputs).toEqual([{propName: 'outputName', templateName: 'outputPropName'}]);
expect(mirror.ngContentSelectors).toEqual([
  '*',                 // first `<ng-content>` in a template, the selector defaults to `*`
  'content-selector-a' // second `<ng-content>` in a template
]);