我一直从我的被动形式中获得一个空值。字段名称是“from”
我的ts档案
ngOnInit() {
this.createForm = new FormGroup({
'title': new FormControl(null, [
Validators.required,
Validators.maxLength(40)
]),
'message': new FormControl(null, [
Validators.required,
Validators.maxLength(130)
]),
'from': new FormControl(null,
Validators.maxLength(40)
)
});
}
我的表格
<form [formGroup]="createForm" (ngSubmit)="onSubmit()">
<div class="form-group">
<label for="">Food Item</label>
<input type="text"
class="form-control"
placeholder="Bacon Egg & Cheese Sandwich"
maxlength="40"
formControlName="title"
>
</div>
<div class="form-group">
<label for="">Customer Message to Recepient</label>
<textarea
class="form-control"
rows="4"
maxlength="130"
formControlName="message"></textarea>
</div>
<div class="form-group">
<label for="">Customers Name</label><br>
<input type="text"
class="form-control"
placeholder="Anonymous"
maxlength="40"
formControlName="from"
>
<small class="text-muted">Leave Blank for Anonymous</small>
</div>
<button class="btn btn-success">Create</button>
</form>
在我的onSubmit()方法中, this.createForm.controls [ '从']。值 继续给我一个空的
谁知道我做错了什么?答案 0 :(得分:1)
反应形式完全符合预期。