Angular · Middle · Question 26 of 75

How do you inject a dependency that might not be provided?

Explanation

Without optional, Angular throws NullInjectorError when no provider is found. Other options include self, skipSelf and host, which limit where the resolution looks.

Further reading

Problem with a question

Angular · Middle · question 26

Test yourself

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

Take this quiz