【问题标题】:ReferenceError: res is not definedReferenceError: res 没有定义
【发布时间】:2019-04-17 08:21:49
【问题描述】:

我是 Angular 新手,我正在开发 Angular 7 应用程序。当我尝试检索数据表单服务时,我在 res 对象中收到此错误“ReferenceError: res is not defined”。

this.http.get(environment.apiURL + '/Item').subscribe((res : Item[])=>{
      console.log(res);
      this.itemList = res;

服务是一个 WebAPI 服务,当我在浏览器中手动粘贴 API URL 时,我正在获取数据

【问题讨论】:

  • 试一试(res : any)
  • 我试过了,还是一样的问题,谢谢
  • 你能做一个stackblitz的例子吗? webApi 的结果是什么?是 JSON 还是文本?
  • 查看网络标签数据时是一个json

标签: angular asp.net-web-api2 angular7


【解决方案1】:

【讨论】:

    【解决方案2】:

    能否检查一下在发送 get 请求之前创建的 api url?

    const url  = environment.apiURL + '/Item';
    console.log(url)
    
    this.http.get(url).subscribe((res : Item[])=>{
      console.log(res);
      this.itemList = res;
    })
    

    【讨论】:

      猜你喜欢
      • 2019-08-07
      • 2016-01-02
      • 2020-07-13
      • 1970-01-01
      • 2017-06-25
      • 2021-03-13
      • 2021-01-16
      • 2018-11-06
      • 1970-01-01
      相关资源
      最近更新 更多