Bug
The feature modules that import MaterialModule (import MdIconModule) will create separated http provider and override the application-wide customized Http.
The following link shows the problem.
http://plnkr.co/edit/hDLOuvRPWxPIY3TwX4GB?p=preview
Cannot use application-wide customized Http in feature module that import MaterialModule
@[email protected]
@angular/[email protected]
Google Chrome Version 57.0.2970.0 (Official Build) dev (64-bit)
Window 10
@alxhub do you have any input on how a component that depends on Http should depend on HttpModule WRT this issue?
I'm facing the same issue. I created a custom http service:
@Injectable()
export class SecureHttp extends Http {
...
}
I provide this service in app.module.ts:
providers: [
{ provide: Http, useClass: SecureHttp }
],
If I don't use Material Design, this SecureHttp service is used in all classes that inject the Http service. But if I do include MaterialModule in other modules as well, the default Http service is used instead of my SecureHttp, because the HttpModule is used in MdIconModule. I can fix this by adding
providers: [
{ provide: Http, useClass: SecureHttp }
],
in each module.
Is this intended behavior?
Had some discussion w/ @alxhub about this. The idea is to change md-icon to optionally inject Http and throw an error if it isn't provided without directly importing the HttpModule itself.
HI @jelbourn , @EladBezalel
Upon your last comment, I thought about this logic.
remove of direct importing of HttpModule and in icon-registry get the Injector and check
if there already Http implementation supplied, if so use it or use the ReflectiveInjector to create the default one.
private getHttp() {
let httpService: Http = this._injector.get(Http ,null);
if (!httpService) {
let providers = (<any>HttpModule).decorators[0].args[0].providers;
let injector = ReflectiveInjector.resolveAndCreate(providers);
httpService = injector.get(Http);
}
return httpService;
}
}
Done in #3792
If I install @angular/material and uninstall @angular/http in a fresh cli project, ng serve wont compile. Is this by design? I expected that the http package did not need to be installed due to it being removed from peerDependencies in 3792.
(I get similar errors with @angular/animations. Only core/common packages are in peerDependencies, even though TS/Webpack require http and animations too).
@csvn please file a new issue
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
_This action has been performed automatically by a bot._