Reputation: 4318
I want to patch a form with slightly different field name. Is this possible in Angular?
Example: suppose this is my student.ts
class.
export class Student {
id: number;
BIValueTerm: number;
}
I want to patch my formgroup with a student object. my formgroup looks like this:
// const student = ... ; student object
const studentForm = new FormGroup({
id: new FormControl(''),
bivalueTerm: new FormControl('')
});
studentForm.patchValue(student);
now the problem is, studentForm
properly patches the id
field but not bivalueTerm
field. Is there any way I can also patch it?
Upvotes: 1
Views: 1747
Reputation: 101
Two way to do get an appropriate result is solution 1:
export class Student {
id: number;
bivalueTerm: number;
}
Solution 2:
studentForm.patchValue(
{
id: student.id,
bivalueTerm: student.BIValueTerm
}
)
Upvotes: 1