Skip to content

Commit 1949817

Browse files
committed
fix(events): override Http Angular to fixed conflicts events
1 parent 6a50d97 commit 1949817

4 files changed

Lines changed: 21 additions & 4 deletions

File tree

src/module.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import { ModuleWithProviders, NgModule, Optional, SkipSelf } from '@angular/core';
2-
import { BrowserXhr, ConnectionBackend, Http as HttpAngular, ResponseOptions, XSRFStrategy } from '@angular/http';
2+
import { BrowserXhr, ConnectionBackend, RequestOptions, ResponseOptions, XSRFStrategy } from '@angular/http';
33
import {
44
DefaultOptionsToken,
55
Events,
66
Http,
77
HttpEvents,
8+
httpFactory,
9+
HttpOverride,
810
HttpPluginsToken,
911
ParseResponsePlugin,
1012
ParseResponseToken,
@@ -35,7 +37,7 @@ export class HttpModule {
3537
useFactory: xhrBackendFactory,
3638
deps: [ BrowserXhr, ResponseOptions, XSRFStrategy, HttpEvents ]
3739
},
38-
HttpAngular,
40+
{ provide: HttpOverride, useFactory: httpFactory, deps: [ ConnectionBackend, RequestOptions ] },
3941
{ provide: ThrowExceptionStatusToken, useValue: null },
4042
{ provide: ParseResponseToken, useClass: ThrowExceptionStatus, deps: [ ThrowExceptionStatusToken ], multi: true },
4143
{ provide: Plugins, useClass: Plugins, deps: [ HttpPluginsToken ] },

src/providers/http.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Inject, Injectable, OpaqueToken, Optional } from '@angular/core';
2-
import { Http as HttpAngular, Response } from '@angular/http';
2+
import { Response } from '@angular/http';
33
import { Config } from '@mbamobi/configuration';
44
import { Request } from '@mbamobi/url-resolver';
55
import 'rxjs/add/observable/defer';
@@ -10,6 +10,7 @@ import 'rxjs/add/operator/toPromise';
1010
import { Observable } from 'rxjs/Observable';
1111
import { HttpEvents } from './backend/xhr_backend';
1212
import { TimeoutException } from './exception';
13+
import { HttpOverride } from './http_override';
1314
import { Mapper } from './mapper';
1415
import { Options } from './options';
1516
import { Plugin, Plugins } from './plugins';
@@ -37,7 +38,7 @@ export class Http {
3738

3839
protected requests: {[key: string]: LastRequest} = {};
3940

40-
constructor(protected http: HttpAngular,
41+
constructor(protected http: HttpOverride,
4142
protected events: HttpEvents,
4243
protected plugins: Plugins,
4344
@Optional() config: Config,

src/providers/http_override.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { Injectable } from '@angular/core';
2+
import { ConnectionBackend, Http, RequestOptions } from '@angular/http';
3+
4+
export function httpFactory(connectionBackend: ConnectionBackend, defaultOptions: RequestOptions) {
5+
return new HttpOverride(connectionBackend, defaultOptions);
6+
}
7+
8+
@Injectable()
9+
export class HttpOverride extends Http {
10+
constructor(connectionBackend: ConnectionBackend, defaultOptions: RequestOptions) {
11+
super(connectionBackend, defaultOptions);
12+
}
13+
}

src/providers/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export * from './backend/xhr_backend';
22
export * from './http';
3+
export * from './http_override';
34
export * from './options';
45
export * from './plugins';
56
export * from './mapper';

0 commit comments

Comments
 (0)