ngFor不显示数组数据,此数据从Firebase检索

阿代尔

嘿,我知道这个问题很多,但是正常的修复方法不起作用。

ts

onChangeFormType(changeFormType) {
this.serverData.getData('questionnaire/' + changeFormType)
  .subscribe(
    (response: Response) => {
      this.formType = response.json();
      let key = Object.keys(this.formType);
      for (let i = 0; i < key.length; i++) {
        this.currentValue.push(this.formType[key[i]])
      }
      console.log('current Value', this.currentValue);
    },
    (error) => console.log('Form Error', error)
  )}

console.log('current Value', this.currentValue);作品中不错。

但是,当我在DOM中运行ngFor循环时,它不起作用。

在此处输入图片说明

html

<div class="col-9" *ngFor="let data of currentValue">
  <div formGroupName="questions">
    <div class="form-Group">{{ data.sno }}</div>
      <br>
      <div class="from-Group">{{ data.question}}</div>
    </div>
  <div formGroupName="options">
    <label>
      <input type="radio" formControlName="op1">{{ data.options}}
    </label></div>
爆炸

optionsquestionsno特性在该元素的属性items的每一个-array data-object。因此,您可以*ngFor在自己的内部嵌套另一个像这样:

<div class="col-9" *ngFor="let data of currentValue">
  <div *ngFor="let item of data.items">
    <div formGroupName="questions">
      <div class="form-Group">{{ item.sno }}</div>
        <br>
        <div class="from-Group">{{ item.question }}</div>
      </div>
    <div formGroupName="options">
      <label>
        <input type="radio" formControlName="op1">{{ item.options }}
      </label>
    </div>
  </div>
</div>

尽管这item.options是一个对象,但您可能希望根据其结构来用另一种方式处理该对象。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章