【问题标题】:Angular 5 Http Post Using WhereAngular 5 Http Post 使用 Where
【发布时间】:2018-01-11 18:39:00
【问题描述】:

我正在使用 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);
    });

【问题讨论】:

  • 你用的是旧的Http服务,还是新的HttpClient服务?
  • 我正在使用新的 HttpClient 服务。
  • 错误在哪一行,或者错误发生在服务器上?
  • 可能是 'uid=' 等号。奇怪的是,在 post 请求上有一个查询参数。
  • 我尝试使用 %3D 而不是 =,但出现 500 服务器错误。错误在服务器的响应中。

标签: angular rest loopback


【解决方案1】:

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

yoururl?variable=value

在你的情况下,你会得到

yoururl?where=uid=999

the documentation 你不能这样做。

【讨论】:

  • 我已经尝试用 %3D 改掉它,但这给了我一个 500 服务器错误
【解决方案2】:

请使用 where 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 => {
      });

【讨论】:

  • 你在后端做远程方法?如果是,请提供代码。
猜你喜欢
  • 2018-09-27
  • 1970-01-01
  • 1970-01-01
  • 2018-08-18
  • 2018-08-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多