Question: Inheritance with dependency injection.
evgenyfedorenko opened this issue · 3 comments
I am facing the following issue: All my resources are inheriting from BaseResource which inherits from Resource. In BaseResource I inject some service like that:
constructor(
http: Http,
protected localStorageService: LocalStorageService
) {
super(http);
}
Now when I call child resource which inherits from BaseResource that dependency is not available since it is not injected explicitly in that resource constructors. This is troublesome to call a constructor for injecting the service in every child resource ( I have more that 20 of them )
Is there a way to inject a service in a Base Resource which will be available in a child resource without explicitly calling the constructor in the child ?
Thank you
In fact, it's an angular question not related to ngx-resource.
You can define your dependencies in your ngModel
providers: [
{provide: YourClass, useClass: YourClass, deps: [All DI HERE]}
]
In that case not need to add construction to each service
Hello all.
I've released some kind of beta of new library which is called rest-core
+ rest-ngx
.
Please check them rest-core
and rest-ngx
.
It works the way like ngx-resource
but has a lot of breaking changes.
Something was removed or simplified.
I've migrated all my projects to the new library.
If you wish to switch to HttpClient or use some other http handlers like fetch
try to migrate your projects to the lib.
Bugs and help requests are welcome in corresponding repos.
Thanks!
PS: Since ngx-resource
is no longer supported by me, closing the issue.
What you mean ngModel? I am not using ngModel just extending the Resource and then all resources are included via forRoot in main module.