小编Lra*_*wls的帖子

Angular 4从API响应中获取标头

我正在向API发送请求,它返回一个数据数组,但我不知道如何从该URL中提取标题,这就是我在服务中尝试过的

@Injectable()
export class ResourcesService {
private resourcesurl = "http://localhost:9111/v1/resources";

constructor(private http: Http) { }

getResources() {
  let headers = new Headers();
  headers.append("api_key", "123456");
  return this.http.get(this.resourcesurl, { headers: headers 
 }).map(this.extractData).catch(this.handleError);
}
getresourceheaders(){
  let headers = new Headers();
  headers.append("api_key", "123456");
  let options = new RequestOptions();
  let testsss = options.headers
  let headerapi = this.http.request(this.resourcesurl, options);
  let test = this.http.get(this.resourcesurl, { headers: headers });
  console.log(headerapi);
}
private extractData(res: Response) {
  let body = res.json();
  return body.data || {};
}
private handleError(error: Response | …
Run Code Online (Sandbox Code Playgroud)

javascript typescript angular

12
推荐指数
3
解决办法
4万
查看次数

标签 统计

angular ×1

javascript ×1

typescript ×1