简体   繁体   中英

Google Sheet API, PUT: this.http.put(…).map is not a function

I'm trying to make a simple PUT call to google sheets API. I followed some of the http.put syntax, but keep getting the error: this.http.put(...).map is not a function.

My code block:

return this.http
           .put(url, JSON.stringify(data), {headers: headers})
           .map(
                (res: any) => {
                   res.json();
                   console.log ("transaction data updated to google seets:"+res.json());
                }
           );

Are you using HTTPClient Module?. Here is the Way of Performing PUT method which is similar to POST method.

return this.http.put<Hero>(this.heroesUrl, data, httpOptions)
    .pipe(
      map(res => {
         console.log(res);
         return res;
      },
      catchError(this.handleError('updateHero', hero))
    );

Did you import ?

import { map } from 'rxjs/operators';

EDIT

You need to import the above, also i would recommend you to use HttpClient instead of HttpModule which would remove the res.json(), your code will look like,

set the options as,

return this.http.put(url, JSON.stringify(formData), this.options)
.pipe(map(response => response.json()));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM