What role does the @Injectable() annotation play?
@Injectable() tells Angular that dependencies can be injected into this class and that it can itself be injected via DI.
Simply put:
- Without
@Injectable(), Angular cannot create an instance if the class has dependencies inside it. - Through the
providedInparameter (e.g.'root') you can specify exactly where this service will be available: at the root of the application, in a module, or in a component.
So @Injectable() makes the class part of the Dependency Injection system.
Short Answer
Interview readyPremium
A concise answer to help you respond confidently on this topic during an interview.