如下所示:
constructor(_backend: ConnectionBackend,_defaultOptions: RequestOptions,private appInitService: AppInitService) {
super(_backend,_defaultOptions);
}
get(url: string,options?: RequestOptionsArgs): Observable
let optionBuf = new RequestOptions({
headers: this.defaultHeaders,params: {'token': this.appInitService.token}
});
//here extend options;
return super.get(url,optionBuf);
}
}
export function myHttpFactory(xhrBackend: XHRBackend,requestOptions: RequestOptions,appInitService: AppInitService): myHttp {
return new myHttp(xhrBackend,requestOptions,appInitService); // 创建myHttp对象
}
export const myHttpProvider = {
provide: myHttp,useFactory: myHttpFactory,deps: [XHRBackend,RequestOptions,AppInitService]
};
以上这篇angular2实现统一的http请求头方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持编程之家。
原文链接:https://www.f2er.com/js/31030.html