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

Too hard to inherit from JwHttp #117

Closed
dlnsk opened this issue Oct 11, 2017 · 7 comments
Closed

Too hard to inherit from JwHttp #117

dlnsk opened this issue Oct 11, 2017 · 7 comments

Comments

@dlnsk
Copy link

dlnsk commented Oct 11, 2017

Because you use injection in constructor's parameters it's very difficult to inherit the service.
Here: https://stackoverflow.com/a/39041953 is good explanation how to use Injector in constructor.
You'll get something like this:

import {Injector} from '@angular/core';

@Injectable()
export class JwtHttp {
  private _http: Http;
  private _shared: SharedService;
  private _config: ConfigService;

  constructor(injector: Injector) {
    this._http = injector.get(Http);
    this._shared = injector.get(SharedService);
    this._config = injector.get(ConfigService);
  }
}

Also need to export JwtRequestOptionsArgs from module.

@dlnsk
Copy link
Author

dlnsk commented Oct 12, 2017

I found solution for my HttpService:

import {Injector} from '@angular/core';

@Injectable()
export class HttpService extends JwtHttp {
  constructor(
    protected injector: Injector
  ) {
    super(injector.get(Http), injector.get(SharedService), injector.get(ConfigService));
  }
}

So, breaking changes may will make in major release. But exports JwtRequestOptionsArgs are important now.

@ronzeidman
Copy link
Owner

Thanks, I've been pretty busy the past couple of months so I didn't have time to update this library. I'll do it next week. Probably sooner if you send a PR.

@ronzeidman
Copy link
Owner

I'm working on an angular 5 version of this library, this will remove JwtHttp and will replace it with an interceptor for the HttpClient

@dlnsk
Copy link
Author

dlnsk commented Nov 2, 2017

What about export JwtRequestOptionsArgs?

@ronzeidman
Copy link
Owner

It will be removed entirely. the Http service is deprecated in Angular 5+
angular/angular#18906

@dlnsk
Copy link
Author

dlnsk commented Nov 2, 2017

Yes, I understude but now in Angular 2 it very necessary. :)

@ronzeidman
Copy link
Owner

Sorry about that...

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

No branches or pull requests

2 participants