Get Angular component's name from the reference

Viewed 18272

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

2 Answers

If you are passing "comp" Component as a class and want to get the class name of that Component.

let compName = this.comp.prototype.constructor.name;
Related