【问题标题】:Error: Undefined data - How to find the problem? - Angular错误:未定义的数据 - 如何找到问题所在? - 角度
【发布时间】:2023-02-20 20:48:11
【问题描述】:

我想从网络服务中显示一些数据。例如:LABEL, ISINCODE, REF

在 JSON 中,结构是这样呈现的:

MET = [
  {
    LABEL: "WILHELMSEN",
    ISINCODE: "NO0010571698",

    RESOLUTION: [
      {
        REF: "01",
      },
    ],

  },

];

检索数据的方法称为getData()

export class ShareholderInformationDetailsComponent implements OnInit {

    private unsubscribe$ = new Subject < void > ();

    arrayMets: ArrayMet[] = [];

    constructor(private service: ShareholderInformationDetailsService) {}


    ngOnInit(): void {
        this.getData();
    }

    getData(): void {
        this.service.getShareholdersDetails().pipe(
            takeUntil(this.unsubscribe$)
        ).subscribe(res => {
            if (res.RETURNCODE === ApiResponseCodeEnum.Ok) {
                console.log("First console ");
                console.log(JSON.stringify(res));
                console.log("---------------");
                console.log("Second console ");
                this.arrayMets = res.ARRAY_MET;
                console.log(JSON.stringify(this.arrayMets))
            }
        });
    }


}

在第一个 console.log 中,我想检查 webService 是否正在与前端通信。我得到数据。

但是,我不明白为什么我在第二个 console.log 中没有看到任何内容?

我收到 undefined 错误消息...

在信息响应文件中,我没有看到我输入的错误?

export interface InformationResponse extends ApiResponse {
    ARRAY_MET: ArrayMet[];
}

export interface ArrayMet {
    LABEL: string;
    ISINCODE: string;
    RESOLUTION: RESOLUTION[];
}; 

export interface RESOLUTION {
    REF: number; 
}

谢谢

【问题讨论】:

    标签: angular


    【解决方案1】:

    您的对象中没有 ARRAY_MET,而是 MET 键;你的界面是错误的。

    【讨论】:

      猜你喜欢
      • 2021-09-14
      • 2018-03-12
      • 2019-03-30
      • 2022-11-23
      • 2016-02-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多