Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Http service to be injected in JsonApiDatastore #4

Closed
acramatte opened this issue Aug 26, 2016 · 4 comments
Closed

Allow Http service to be injected in JsonApiDatastore #4

acramatte opened this issue Aug 26, 2016 · 4 comments

Comments

@acramatte
Copy link

I am using this angular2-jsonapi in the context of an Nativescript application. We use Nativescript-angular's NS_HTTP_PROVIDERS instead of HTTP_PROVIDERS. They basically extend the Http from Angular.

My issue is that the JsonApiDatastore completly ignores the provided Http from NS because it always creates an injector from the HTTP_PROVIDERS so none of my calls to our json-api work.

I think that, ideally, the http service should be injected directly in the JsonApiDatastore because it is the reponsiability of the consumer of this library to provide it.

@ghidoz
Copy link
Owner

ghidoz commented Aug 26, 2016

I absolutely agree. My first attempt was exactly what you are suggesting. This was the JsonApiDatastore constructor:

constructor(private http: Http) { }

and you should have to configure your datastore like this:

export class Datastore extends JsonApiDatastore {

  constructor(http: Http) {
    super(http);
  }
}

The problem was this error:

`Argument of type 'Http' is not assignable to parameter of type 'Http'.
Property '_backend' is protected but type 'Http' is not a class derived from 'Http'.``

and, after many researches, the only way to solve was creating an injector for the HTTP_PROVIDERS. If you can solve this, I'll be happy to inject the Http service directlty in JsonApiDatastore.

Thanks!

@acramatte
Copy link
Author

Argument of type 'Http' is not assignable to parameter of type 'Http'. Property '_backend' is protected but type 'Http' is not a class derived from 'Http'.`

That is weird. I have exactly the same changes you wrote in my fork but for me everything works fine.

Did you have different versions of angular between the app consuming this library and this library itself ?

@ghidoz
Copy link
Owner

ghidoz commented Sep 2, 2016

Ok, I discovered the problem. I'm developing this library using npm link and there is some strange bug with dependencies. If I npm install it or if I just copy it in node_modules folder, it works.
I'll make your suggested change in the next release ;)

@ghidoz ghidoz closed this as completed in 1e567c5 Sep 2, 2016
@acramatte
Copy link
Author

Thanks @ghidoz 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants