角度 5 http post 使用在哪里



我正在使用Loopback后端REST API和Angular 5前端。但是,我无法让 post 函数工作 - 我总是收到错误"值不是对象"。

   this.http.post(url, {
      "displayName": user.displayName,
      "email": user.email,
      "uid": user.uid,
      "photoURL": user.photoURL,
      "phoneNumber": user.phoneNumber,
      "verifiedPhone": user.verifiedPhone
    }, {params: new HttpParams().set('where','uid=' + user.uid)}).subscribe( res => {
      console.log("results of updating user: ", res);
    });

当你在帖子中使用httpParams时,你的网址会发生变化,比如

yoururl?variable=value

在您的情况下,您将获得

yoururl?where=uid=999

请参阅文档 您不能这样做。

请使用 Like:

let param = {
          where: { search: search },
          skip: 0,
          limit: 6
        }
   const headers = new Headers({ 'Content-Type': 'application/json' });
this.http.post(url, param, { headers }).subscribe(response => {
  }, err => {
      });

相关内容

最新更新