代码之家  ›  专栏  ›  技术社区  ›  Aragorn

googlesheetapi,PUT:this.http.PUT(…).map不是函数

  •  0
  • Aragorn  · 技术社区  · 6 年前

    我想做个简单的决定 PUT 调用googlesheetsapi。我跟踪了一些 http.put this.http.put(...).map is not a function.

    我的代码块:

    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());
                    }
               );
    
    2 回复  |  直到 6 年前
        1
  •  1
  •   Sajeetharan    6 年前

    你进口了吗?

    import { map } from 'rxjs/operators';
    

    您需要导入上述内容,我建议您使用HttpClient而不是HttpModule,因为HttpModule会删除res.json(),您的代码如下所示,

    return this.http.put(url, JSON.stringify(formData), this.options)
    .pipe(map(response => response.json()));
    
        2
  •  1
  •   Suresh Kumar Ariya    6 年前

    您正在使用HTTPClient模块吗?。下面是执行PUT方法的方法,它类似于POST方法。

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