嘿,我知道这个问题很多,但是正常的修复方法不起作用。
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>
的options
,question
和sno
特性在该元素的属性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] 删除。
我来说两句