EXCEPTION: No provider for Headers! (App -> Api -> Headers)

我只是一个虾纸丫 提交于 2019-12-01 16:02:21

The Headers class can't be injected. You need to instantiate it by your own:

constructor(http: Http) {
  let headers = new Headers();
  headers.append('Content-Type', 'application/json');
  headers.append('Access-Control-Allow-Origin', '*');
  this.people = http.get('http://www.mocky.io/v2/5715f13a1100004d1187d9e1', { headers: headers })
    .map(response => response.json());
}
Günter Zöchbauer

There is no need to inject Headers. Just create it with

let headers = new Headers();
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!