-1

我有以下问题:我尝试使用 ngfor 获取“place”的值。以下我使用:

.html
<ng-container *ngFor="let se of List" 

跟随Json:

.json
 "place": [
    {
      "id": 1,
      "name": "Ort",
      "number": "Nummer",
      "type": "Art",
      "height": 20,
      "width": 42,
      "lagerin": [
        {
          "id": 1,
          "secnname": "Regal  ",
          "secnnumber": "R1",
          "sectype": {
            "sectypename": "Big ",
            "ro": 5,
            "co": 2,
            "secheight": 20,
            "secwidth": 6,
            "secdepth": 1,
            "sectco": 1
          }
        },
        {
          "id": 2,
          "secnname": "Reg 2 ",
          "secnnumber": "R2",
          "sectype": {
            "sectypename": "Small",
            "ro": 3,
            "co": 3,
            "secheight": 25,
            "secwidth": 4,
            "secdepth": 2,
            "sectco": 2
          }
        }
      ]
    }
  ]

我得到上面的错误。所以我的想法是在“地方”获取属性以在我的代码中使用它们。在我添加“lagerin”之前,它工作正常。但我需要这个“到位”。

.ts
  ngOnInit() {
    this.route.queryParams
      .subscribe(params => {
        this.id = params.id;
      });
    if (this.id) {
      this.service.gelager(this.id).subscribe(data => {
        if (data) {
          this.List= data;
        } else {
          console.log('No lager available');
        }
      });
    }
  }
4

1 回答 1

0

如果您的getLager方法返回您向我们展示的 Json,那么您应该拥有

this.list = data.place

而且你的局部变量不应该以大写字母开头,这只是一个约定

于 2020-08-31T15:30:50.783 回答