渲染angular2 HashMap <string,string <列表>>

时间:2019-01-19 12:01:11

标签: angular hashmap

当我尝试打印HashMap时遇到问题>

上周,我有一个关于在Java 8中将两个字段分组的问题,我在这里解决了这个问题,现在我找不到关于如何在angular2中打印项目响应的任何信息。

我收到的答复是这个。

https://jsoneditoronline.org/?id=de29279e1eaa495188c36169ae9a23ce

使用angular2,我具有以下组件

ngOnInit() {
    this.matchesService.getMatches()
                        .subscribe(
                        data => {
                            this.matches = data;
                        console.log(this.matches["Alemania[EN]"]["ACB[EN]"][0]);
                          },
                      )
  };

此组件可以在控制台中正确打印响应,但我不知道如何呈现。

在html中,我输入了

{{this.matches}} 

然后打印以下对象

[[object Object]]

我需要正确渲染对象。

2 个答案:

答案 0 :(得分:2)

尝试使用键值管道:

<p>
    Map looping template side (keyvalue pipe) :
</p>

<ul>
  <li *ngFor="let recipient of map | keyvalue">
    {{recipient.key}} -->
      <span *ngFor="let item of recipient.value | keyvalue">
        {{item.key}}
        <span *ngFor="let element of item.value">
          <ul>
            <li>{{element.id}}</li>
          </ul>
        </span>
      </span>
  </li>
</ul>

DEMO

答案 1 :(得分:0)

此行为是正确的。

如果匹配项是列表,则可以使用* ngFor。 它的工作就像一个循环,在html中。 然后,您可以打印每个值。

请阅读以下内容: https://angular.io/guide/displaying-data#showing-an-array-property-with-ngfor

(您不必在html中使用此关键字)