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

后端 未结 2 1492
灰色年华
灰色年华 2021-01-17 16:48

Just cant figure out why I have still getting this missing Headers provider issue.

My bootstrap.ts:

import {enableProdMode, provide} from \"angular2/         


        
2条回答
  •  野的像风
    2021-01-17 17:26

    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());
    }
    

提交回复
热议问题