Type 'Headers' is not assignable to type 'HttpHeaders | { [header: string]: string | string[]; }'

2.8k views Asked by At

AuthServiceProvider

postData(credentials, type){

    return new Promise((resolve, reject) =>{
      let headers = new Headers();
      this.http.post(apiUrl+type, JSON.stringify(credentials), {headers: headers}).
      subscribe(res =>{
        resolve(res.json());
      }, (err) =>{
        reject(err);
      });

    });

  }

Argument of type '{ headers: Headers; }' is not assignable to parameter of type '{ headers?: HttpHeaders | { [header: string]: string | string[]; }; observe?: "body"; params?: Ht...'. Types of property 'headers' are incompatible. Type 'Headers' is not assignable to type 'HttpHeaders | { [header: string]: string | string[]; }'. Type 'Headers' is not assignable to type '{ [header: string]: string | string[]; }'. Index signature is missing in type 'Headers'.

1

There are 1 answers

0
Najam Us Saqib On

Try Like this:

postApi(link, data){
     let headers = {'Content-Type':'application/json'};
    return new Promise(resolve => {
        this.http.post(this.globalUrl+link, JSON.stringify(data), {headers: headers})
        .subscribe(data => {
            resolve(data);
        },
        (err) => {
            console.log("Error" + err)
        })
    });
}