如何使用对象类型的 @Input() 值填充表单?
How can I populate a form with an @Input() value that is of type object?
这是我提到的带有输入的 ts
@Input() event: ClassEvent //this is the input
start-date: FormControl;
end-date: FormControl;
class : FormControl;
myForm: FormGroup;
这是表格的一部分
<div class="form-group">
<select id="location_id" formControlName="class"
required>
<option value="" disabled selected>Classes</option>
<option *ngFor="let class of classList">
{{class.name}}</option>
</select>
</div>
</div
我想 patchValue
就是您想要的。您可以在 FormGroup
上找到这种方法。
举个例子...
ngOnInit(){
// ...
myForm.patchValue(selectedEvent);
}
这里有更多信息 - https://angular.io/guide/reactive-forms
这是我提到的带有输入的 ts
@Input() event: ClassEvent //this is the input
start-date: FormControl;
end-date: FormControl;
class : FormControl;
myForm: FormGroup;
这是表格的一部分
<div class="form-group">
<select id="location_id" formControlName="class"
required>
<option value="" disabled selected>Classes</option>
<option *ngFor="let class of classList">
{{class.name}}</option>
</select>
</div>
</div
我想 patchValue
就是您想要的。您可以在 FormGroup
上找到这种方法。
举个例子...
ngOnInit(){
// ...
myForm.patchValue(selectedEvent);
}
这里有更多信息 - https://angular.io/guide/reactive-forms