1
嗨我想问一下创建自定义http类来处理基本URL并设置默认超时。自定义HTTP类Angular 2更改基本URL并设置超时
我已经实现这myhttp类:
import { Injectable } from '@angular/core';
import { Http, Request, RequestOptions, ConnectionBackend, RequestMethod, RequestOptionsArgs, Headers } from '@angular/http';
import { Observable } from 'rxjs/Observable';
import { Configuration } from '../config/configuration';
import { PageNavigationService } from './page-navigation.service';
@Injectable()
export class MyHttp extends Http {
serviceBase: string;
timeout: number;
constructor(
backend: ConnectionBackend,
defaultOptions: RequestOptions,
private _pageNavigationService: PageNavigationService) {
super(backend, defaultOptions);
this.serviceBase = Configuration.SERVICE.BASE_URL;
this.timeout = Configuration.SERVICE.TIME_OUT;
console.log('get: ' + this.serviceBase);
}
}
,这是我main.ts
bootstrap(AppComponent,
[
appRouterProviders,
HTTP_PROVIDERS,
PageNavigationService,
{
provide: Http,
useFactory: (backend: XHRBackend,
defaultOptions: RequestOptions,
_pageNavigationService: PageNavigationService) => new MyHttp(backend, defaultOptions, _pageNavigationService),
deps: [XHRBackend, RequestOptions, PageNavigationService]
}
]).catch(err => console.error(err));
,但它不工作,任何人都可以请指导?
我在这种情况下使用角度RC 4。 – gunchungpyo
需要更多信息 - 控制台中是否出现错误?是应该发生的事情,但不是? – peppermcknight