我正在尝试Angular Reactive表单我正在尝试使用来自我的服务器的数据填充下拉列表,在获取数据后,我的下拉列表显示所有选项但是带有空白文本,这是什么原因?
我的html表单的小版本
<form [formGroup]="new_element">
<div>
<input formControlName="title" />
</div>
<div>
<select formControlName="question">
<option *ngFor="let op of questions" [value]="op.questionId" >{{op.title}}</option>
</select>
</div>
</form>
我恢复版的组件类
questions: array<Question> = []
new_element: FormGroup;
constructor(private fb: FormBuilder,
private new_elService: NewElementService,
private question_service: QuestionService) {
// get questions from server for select calling question_service.getAll() method which is an observable
this.createForm()
}
createForm() {
this.new_element = this.fb.group({
title: ['', Validator.required],
question: ['', Validator.required]
})
}
但后来我得到的错误是我的问题的标题,我该怎么办?