首页 > 解决方案 > 为什么 StackBlitz 中没有显示 mat-accordion?

问题描述

我正在开发一个测验应用程序,当您单击“查看详细摘要”链接时,带有问题和答案摘要的实际 mat-accordion 似乎没有显示在我的 ResultsComponent 中的 StackBlitz 中。仅显示展开/折叠按钮。请在此处查看我的 StackBlitz:https ://stackblitz.com/edit/angular-9-quiz-app

标签: angularangular-material

解决方案


你有结果

*ngFor="let panel of accordionList; let question of quizData.questions; index as i"

您不能使用 *ngFor 的这种类型(此外,accordionList 什么都不是)

必须是(我想)

*ngFor="let question of quizData.questions; index as i"

*更新了下面还有一个错误,你有

 *ngFor="let finalAnswer of finalAnswers;
         let correctAnswer of correctAnswers"

如果你想拥有两个 *ngFor 使用一个,你就无法做到这一点<ng-container>

<div *ngFor="let finalAnswer of finalAnswers">
   <ng-container *ngFor="let correctAndser of correctAnswers>
        ...
   </ng-container>
</div>

或者如果两个数组的长度相同,则使用索引

<div *ngFor="let finalAnswer of finalAnswers;let i=index">
   {{correctAnswers[i]}}
</div>

推荐阅读