troyanskiy/ngx-resource

Cannot inject custom provider to Resource after updating to 2.1.0

desfero opened this issue · 2 comments

Hello,
after upgrading to 2.1.0 Injector was removed from Resource class, but i used it for injecting my custom dependency do an AuthResource.

export class AuthResource extends Resource {
  constructor(http: Http,
              injector: Injector) {
    super(http, injector);

    const headersService = injector.get(HeadersService);
    // ...
  }

do we have any options to get same functionality after this change?

Hello.
Yes, the Injector has been removed from Resource.

Please try to do like that

@ResourceParams({
...
add2Provides: false
})
export class AuthResource extends Resource {
  constructor(http: Http,
              private headersService: HeadersService) {
    super(http);

    // ...
  }

Add the resource class to your app providers list.

After some diggings with this problem i remove import (ResourceModule) from my application and inject all resources by myself (fixing also aot issue with this approach). More information about AOT available in #102