I am working with an Angular2 model that I'm filling with data from a service. My goal is to use this model to update a form (created using FormBuilder) so that users can easily edit the information.
Although my current approach works, I encounter errors for fields in my model that don't have corresponding form controls.
...
ngOnInit(): void {
this.buildForm();
this.fetchData('1');
}
fetchData(id: string) {
this.myModelsService.get(id)
.subscribe(
data => {
this.myModel = data;
this.myForm.setValue(data);
},
error => console.log(error)
);
}
While this method is functional, I keep getting errors like
Cannot find form control with name: incidentTimeStamp
.
Should I start by removing attributes that don't have matching form controls? Or are there better strategies to achieve what I need?
Populating fields for editing is a fundamental requirement, and it seems more complex than necessary in this case.