我想将属性从api调用传递给Submit函数,但不确定为什么它不起作用。我认为这与选择或重新格式化输入有关。
遇到错误Error: No value accessor for form control with name: 'employee_id'
form.component.html
<select>
<option
*ngFor="let employee of employees"
name="employee_id"
[(ngModel)]="employee_id">
{{ employee.name }}
</option>
</select>
<button
(click)="submitMeetingRequirements()"
class="btn btn-success">
Suggest Meeting
</button>
这是来自form.component.ts
submitMeetingRequirements() {
this._meetingService.submitMeetingRequirements(
this.employee_id)
.subscribe(res => this.suggestions = res["suggestions"])
}
答案 0 :(得分:1)
已修复
<select [(ngModel)]="employee_id" name="employee_id">
<option
*ngFor="let employee of employees"
value="{{employee.id}}">
{{ employee.name }}
</option>
</select>
答案 1 :(得分:0)
在select
标签上使用 [(ngModel)]
,而不要在option
标签上使用。像这样:
<select [(ngModel)]="employee_id">
<option
*ngFor="let employee of employees"
name="employee_id" >
{{ employee.name }}
</option>
</select>
<button
(click)="submitMeetingRequirements()"
class="btn btn-success">
Suggest Meeting
</button>
这是您推荐的Working Sample StackBlitz。