【发布时间】:2016-12-13 07:31:32
【问题描述】:
所以基本上我需要将自定义身份验证标头添加到所有引用 API 的请求。在构造函数中我想添加这个标题,然后在类方法中使用this.http
import { Injectable } from '@angular/core';
import { Config, Events } from 'ionic-angular';
import { Http } from '@angular/http';
@Injectable()
export class APIRequest {
constructor (
private http: Http,
private config: Config,
) {
this.http.headers.append('My-Custom-Header','MyCustomHeaderValue');
}
}
【问题讨论】:
-
@SabbirRahman 不,我不想在每种方法中设置标题。我需要在构造函数中设置一次。
-
您可以创建另一个服务并在那里包装 HTTP。所以有 post, get, .... 与您的自定义标题。
标签: angular typescript ionic2