Is there a way to get a components name in Angular from the reference?
So, having something like this:
@Input comp: any;
ngOnInit {
console.log(this.comp);
}
will log the whole component object, but I want only a string with the name of the component.
Is that possible? Thanks
Yes it is definitely possible using this.constructor.name
. This will give you the name of the current component.
this.constructor.name
In your case you can try doing
this.comp.constructor.name
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With