One of my challenges involves a form that directly updates an object in the following manner:
component.html
<input type="text" [(ngModel)]="user.name" />
<input type="text" [(ngModel)]="user.surname" />
<input type="text" [(ngModel)]="user.age" />
component.ts
user = {
name: null,
surname: null,
age: null
}
Within my component.html, there is a save button implemented in a child component.
<app-save-btn [user]="user"></app-save-btn>
In the app-save-btn
component, I am utilizing OnChanges
to detect changes.
@Input() user: User;
userForCompare: User;
ngOnChanges() {
if (!this.userForCompare) {
this.userForCompare = {...this.user};
}
console.log(this.userForCompare, this.user);
}
My issue arises when I update additional fields beyond the initial ones - I do not receive updated change information.
While I understand that I could create individual variables for each field, as I have approximately 30 fields, I would prefer to keep my current implementation relatively unchanged...
Any assistance or guidance on this matter would be greatly appreciated.