Html 角度-动态填充表格

Html 角度-动态填充表格,html,angular,typescript,Html,Angular,Typescript,我发现很难找到与我的问题相关的标题。我通过做一个项目来学习angular,这个项目包括准备表格。每个表单都可以包含存储在一个名为Questions(FormId、Name、Message)的表中的各种字段。当用户填写表单时,数据存储在一个名为Answer(QuestionId,Value)的表中。到目前为止,一切都很顺利 我的问题是当我想在html表中显示答案时。我尽我所能,但没有取得令人满意的结果 这是我的密码: <table class="table table-striped

我发现很难找到与我的问题相关的标题。我通过做一个项目来学习angular,这个项目包括准备表格。每个表单都可以包含存储在一个名为Questions(FormId、Name、Message)的表中的各种字段。当用户填写表单时,数据存储在一个名为Answer(QuestionId,Value)的表中。到目前为止,一切都很顺利

我的问题是当我想在html表中显示答案时。我尽我所能,但没有取得令人满意的结果

这是我的密码:

    <table class="table table-striped">
    <thead class="thead-dark">
        <tr>
            <th *ngFor="let item of keyValueRep | keyvalue">{{ item.key }}</th>
        </tr>
    </thead>
    <tbody>
        <tr *ngFor="let k of keyValueReponses">
            <td *ngFor="let i of k | keyvalue">{{ i.value }}</td>
        </tr>
    </tbody>
</table>

this.idForm = this.route.snapshot.paramMap.get('id');
if(this.idForm){
        questionService.getQuestionsByForm(this.idForm)
        .subscribe(response => {
          this.questions = response.json();
          let rep: Reponse[] = []

          //*/
          this.questions.forEach(q => {
            this.reponseService.getReponsesByQuestion(q.Id)
            .subscribe(response => {
              rep = response.json();
              console.log(rep)

              this.reponses.push(rep);


              rep.forEach(r => {
                this.reponses.push(r.Valeur);
                this.keyValueRep[r.Question.Name] = r.Valeur;
              });
              console.log(this.keyValueRep);
              this.keyValueReponses.push(this.keyValueRep);
            });
            this.keyValueRep = {};
          });
          console.log(this.keyValueReponses);//*/
        });

      }

{{item.key}
{{i.value}}
this.idForm=this.route.snapshot.paramMap.get('id');
如果(此.idForm){
questionService.getQuestionsByForm(this.idForm)
.订阅(响应=>{
this.questions=response.json();
让代表:响应[]=[]
//*/
this.questions.forEach(q=>{
this.reponseService.getReponsesByQuestion(q.Id)
.订阅(响应=>{
rep=response.json();
console.log(rep)
这个.responses.push(rep);
rep.forEach(r=>{
这个。应答。推(r.Valeur);
this.keyValueRep[r.Question.Name]=r.Valeur;
});
console.log(this.keyValueRep);
this.keyValueResponses.push(this.keyValueRep);
});
this.keyValueRep={};
});
console.log(this.keyValueResponses)//*/
});
}
我想知道是否有一个简单的方法来做这件事。如果有人有主意,我将不胜感激


提前谢谢。

您尝试两次推送回复,一次全部推送,其他时间一个接一个推送<代码>this.keyValueResponses.push(this.keyValueRep)应该在rep.foreach中。您是否有任何可以使用的钩子
getReponsesByQuestion()
API?感谢您的回复@GopeshSharma我只是在尝试一些关于可变响应的东西。唯一重要的变量是keyValueRep和KeyValueResponse。我试了你的建议。它不起作用。getReponsesByQuestion()是一个API调用(返回this.http.get(this.urlQuest+'/'+id);)。