我无法检索表单值,它以某种方式让我不确定我做错了什么?
我的HTML:
<form enctype="multipart/form-data" #studentUploadForm="ngForm" (ngSubmit)="onSubmit(studentUploadForm)">
<label for="exampleInputFile">Examen:</label>
<div class="form-group">
<select [(ngModel)]="examen_id" name="examenId" class="form-control">
<option [ngValue]="examen.id" *ngFor="let examen of examensStudent">{{examen.naam}}</option>
</select>
</div>
<label for="exampleInputFile">Bestand:</label>
<input type="file" class="form-control-file" id="exampleInputFile" aria-describedby="fileHelp">
<small id="fileHelp" class="form-text text-muted">Upload hier de examen die je wilt inleveren.</small>
<button type="submit" class="pxl-knop">Upload</button>
</form>
我的TS:
export class StudentUploadComponent implements OnInit {
@Input() examensStudent: Examen[] = [];
examen_id = 1;
constructor(private serv: ExamService) { }
onSubmit(form) {
console.log(form.examen_id); //This is returning undefined
}
ngOnInit() {
this.serv.getExams().subscribe(data => this.examensStudent = data);
}
}