Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Angular component's name from the reference

Tags:

angular

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

like image 827
David Avatar asked May 17 '17 14:05

David


1 Answers

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
like image 95
Amit Chigadani Avatar answered Sep 18 '22 14:09

Amit Chigadani