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

后端 未结 2 1490
灰色年华
灰色年华 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());
    }
    
    0 讨论(0)
  • 2021-01-17 17:32

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

    let headers = new Headers();
    
    0 讨论(0)
提交回复
热议问题