Angular · Junior · Question 30 of 75

How do you get a service instance inside a component?

Explanation

Dependency injection supplies the instance, so all components share one object and tests can replace it with a fake. new creates an unrelated copy and hard-wires the dependency.

Further reading

Problem with a question

Angular · Junior · question 30

Test yourself

Take the Angular · Junior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz