Эй, я знаю, что этот вопрос часто возникает, но обычные исправления не работают.
Это мой код
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);
хорошо работает.
Но когда я запускаю цикл ngFor в DOM, он не работает.