Javascript 如何在Angular中使用带有keyvalue管道的插入循环

Javascript 如何在Angular中使用带有keyvalue管道的插入循环,javascript,angular,typescript,Javascript,Angular,Typescript,我的答案课 import { Question } from './question'; export class Answer { AnswerId: number; Content: string; IsCorrect: boolean; Mark: number; QuestionId: number; Question: Question; } 我的TestStartComponent testInfo: Map<stri

我的答案课

import { Question } from './question';

export class Answer {
    AnswerId: number;
    Content: string;
    IsCorrect: boolean;
    Mark: number;
    QuestionId: number;
    Question: Question;
}
我的TestStartComponent

    testInfo: Map<string, Answer[]>;
    id: number;
    loaded: boolean = false;

    constructor(private dataService: DataService, activeRoute: ActivatedRoute) {
        this.id = Number.parseInt(activeRoute.snapshot.params["id"]);
    }

    ngOnInit() {
        if (this.id)
            this.dataService.getTestStart(this.id)
                .subscribe((data: Map<string, Answer[]>) => {
                    this.testInfo = data; this.loaded = true;});
    }
我的test-start.component.html

<div *ngIf="loaded">
    <table class="table table-striped">
        <thead>
            <tr>
                <td>Вопрос</td>
                <td>Вариант 1</td>
                <td>Вариант 2</td>
                <td>Вариант 3</td>
                <td>Вариант 4</td>
                <td>Вариант 5</td>
            </tr>
        </thead>
        <tbody>
            <tr *ngFor="let item of testInfo | keyvalue">
                <td class="row-number-column">{{item.key}}</td>
                <td>{{item.value}}</td>
                <!--<td *ngFor="let s of testInfo[item] | keyvalue">
                    {{s.content}}
                </td>-->
                <!--<template *ngFor="let s of testInfo[item] | keyvalue">
                    <td>
                        {{s.content}}
                    </td>
                </template>-->
            </tr>
        </tbody>
    </table>
</div>
我想在test-start.component.html中查看它们的所有键和值,但我不能使用nestedinserted循环输出值


因此,问题是,如何为每个键输出所有值?

keyvalue管道用于迭代对象属性,而不是数组。您有一系列答案,因此您只需将其传递给ngFor即可。但是,如果需要,也可以打印答案的所有键值

<tr *ngFor="let answer of testInfo">
  <td class="row-number-column">{{answer.answerId}}</td>
  <td>{{answer.content}}</td>
  <td *ngFor="let item of answer| keyvalue">
    {{item.key}} : {{item.value}} <br>
  </td>
</tr>

这就是我解决问题的方法

            <tr *ngFor="let item of testInfo | keyvalue">
                <td class="row-number-column">{{item.key}}</td>
                <td *ngFor="let s of testInfo[item.key]">
                    {{s.content}}
                </td>
            </tr>