小编Utk*_*rma的帖子

如何在角度2中添加标题到帖子请求?

//In services.ts

import { Injectable } from '@angular/core';
import { Http, Headers, RequestOptions } from '@angular/http';
import 'rxjs/Rx';
@Injectable()
export class DataService {

constructor(private http: Http) {   }
fetch(){
   return this.http.get('json-object-link').map(
      (res) => res.json()
    )
       }

 }

//In component

 ngOnInit() {

 this.dataService.fetch()
    .subscribe(
      (data) => this.ninjas = data
    );
}
Run Code Online (Sandbox Code Playgroud)

我想在此请求中添加以下标头:
"headers":
{
"content-type":"application/json",
"access_token":"abcd"
}

angular2-http angular

7
推荐指数
1
解决办法
1万
查看次数

标签 统计

angular ×1

angular2-http ×1