Optiq
Optiq

Reputation: 3182

What is the type of an Angular 13 component?

I'm creating a component that receives another component through an input which you can see in this stackblitz demo. If you look at the @Input() of the ParentComponent you'll see it's defined as

@Input() ComponentToEmbed : eComponentType<Component>;

I came across this StackOverflow question from 4 years ago, which suggested using ComponentType<T>, which is what made me try it. However, in my Angular 13 app, there is no such a thing as ComponentType being found when I begin typing. I looked on the doc pages and didn't see anything mentioning ComponentType<T>. What should I do to type the @Input() properly?

Upvotes: 2

Views: 2156

Answers (2)

A. Milosavljević
A. Milosavljević

Reputation: 661

Based on you stackblitz example, it looks like Type<Component> should do the trick.

import { Type } from '@angular/core';
...

@Input() ComponentToEmbed : Type <Component>;
...

Upvotes: 2

Vikas
Vikas

Reputation: 12036

ComponentType<T> is part of Angular Material CDK

/** Interface that can be used to generically type a class. */
export interface ComponentType<T> {
    new (...args: any[]): T;
}

Upvotes: 2

Related Questions