【发布时间】:2018-04-30 11:03:02
【问题描述】:
嘿,我知道这个问题经常出现,但正常的修复方法不起作用。
这是我的代码
export class CourseReviewFormComponent implements OnInit {
form: FormGroup
questionnaire: string[] = [];
currentQuestionsValue: string[] = [];
constructor(private serverData: ServerService) { }
ngOnInit() {
this.onGetForm();
}
onGetForm() {
this.serverData.getData('questionnaire/Student Course Review')
.subscribe(
(response: Response) => {
this.questionnaire = response.json();
let key = Object.keys(this.questionnaire);
for (let i = 0; i < key.length; i++) {
this.currentQuestionsValue.push(this.questionnaire[key[i]].items)
}
console.log('current Questions Value', this.currentQuestionsValue);
},
(error) => console.log('Form Error', error)
)
}
}
我的模板
<form>
<div *ngFor="let data of currentQuestionsValue">
<strong> {{ data.sno }}). </strong>
<span>{{ data.question}}</span>
<div>
<label *ngFor="let op of data.options; let i = index">
<input type="radio" name="option" [value]="i">
<span>{{ op }}</span>
</label>
</div>
</div>
</form>
但是 ngFor 不显示任何数据:
在console.log('current Value', this.currentValue); 中效果很好。
【问题讨论】:
-
查看控制台输出,
currentQuestionsValue是一个只有一个元素的数组(也是一个数组)。那个内部数组很可能就是你要找的那个。 -
你能告诉我我在 dom 中的显示方式吗
-
使用
this.currentQuestionsValue = this.currentQuestionsValue[0]它会为你解决问题。
标签: angular typescript firebase firebase-realtime-database angular-forms