1

I have an component in Angular:

export class StudentsComponent implements OnInit, OnDestroy {
}

In another component I tried to display name of class StudentsComponent preliminarily imported StudentsComponent:

console.log(StudentsComponent.constructor.name);

Why it gives me in console Function instead StudentsComponent?

1 Answer 1

1

StudentsComponent is a constructor. It itself is constructed by the Function constructor. Use StudentsComponent.name.

Sign up to request clarification or add additional context in comments.

2 Comments

Always to get class name to use .name?
@OPV a class is just a function that can only be constructed. All functions have a name property.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.