What is @Injectable Decorator in angular?

What is @Injectable Decorator?

You must apply the @Injectable decorator if you are defining a class that will be instantiated using the Angular dependency injection feature and that class’s constructor has its own dependencies. I didn’t need to apply this decorator to the Repository class ​​ because there was no constructor, but now that there is a dependency on an Http object, the @Injector decorator must be applied.



export class Repository {


As Angular resolves the dependencies to create a new object, the @Injectable decorator indicates that it needs to resolve the constructor parameters. If you forget to apply the @Injectable decorator, the application will compile but won’t run, and you will see an error like this in the browser’s JavaScript console:

Error: Can't resolve all parameters for MyClass

(Visited 25 times, 1 visits today)

Leave a Reply

Your email address will not be published. Required fields are marked *