angular - 从 onSubmit 值获取未定义
问题描述
我无法检索它以某种方式一直给我不确定的表单值我做错了什么?
我的 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);
}
}
解决方案
推荐阅读
- javascript - 将支付功能与 PayPal Checkout paypal.Button.render 方法分离
- java - IntelliJ-Idea 生成实体面临的问题
- xml - 整数数据类型的有效值
- regex - 有没有办法匹配字符串:字符串中具有变量定位的数字?
- vue.js - 将对象添加到数组时未清理 V-Model (Vue-Js)
- javascript - 我可以使用 args1>args2 吗?args1:javascript 中的 args2 语句?
- amazon-web-services - Capistrano 在部署后创建一个新的 ami
- sql-server - 如何从 sql server 中的 ExperienceHistory 表中计算总经验?
- c# - 有什么方法可以对 Azure SQL 数据库更改做出反应?
- postgresql - 如何在 PostgreSQL 中按查询编写组