My requirement is to fill textboxes with their corresponding value from database to when the textbox changed. For instance, if the value Mary is enter in name textbox then its corresponding row from the database table such as spoon and plate should be displayed in store A and store B textbox.
Id | Name | Store A | Store B |
---|---|---|---|
1 | Julie | Knife | Pot |
2 | Mary | Spoon | Plate |
Component.ts
<code> public orderForm = new FormGroup({
Id: new FormControl(null),
Name: new FormControl(null),
StoreA: new FormControl(null),
StoreB: new FormControl(null),
});
Name: string = '';
Store_A: string = '';
Store_B: string = '';
updateOtherFields(args: any): void {
if (this.orderForm) {
this.service.getData(args.orderForm.Name).subscribe((data) => {
this.Store_A = args.itemData.StoreA;
this.Store_B = args.itemData.StoreB;
});
} else {
this.Store_A = '';
this.Store_B = '';
}
}
</code>
<code> public orderForm = new FormGroup({
Id: new FormControl(null),
Name: new FormControl(null),
StoreA: new FormControl(null),
StoreB: new FormControl(null),
});
Name: string = '';
Store_A: string = '';
Store_B: string = '';
updateOtherFields(args: any): void {
if (this.orderForm) {
this.service.getData(args.orderForm.Name).subscribe((data) => {
this.Store_A = args.itemData.StoreA;
this.Store_B = args.itemData.StoreB;
});
} else {
this.Store_A = '';
this.Store_B = '';
}
}
</code>
public orderForm = new FormGroup({
Id: new FormControl(null),
Name: new FormControl(null),
StoreA: new FormControl(null),
StoreB: new FormControl(null),
});
Name: string = '';
Store_A: string = '';
Store_B: string = '';
updateOtherFields(args: any): void {
if (this.orderForm) {
this.service.getData(args.orderForm.Name).subscribe((data) => {
this.Store_A = args.itemData.StoreA;
this.Store_B = args.itemData.StoreB;
});
} else {
this.Store_A = '';
this.Store_B = '';
}
}
html
<code> <input type="text" [(ngModel)]="Name" (ngModelChange)="updateOtherFields()">
<input type="text" [(ngModel)]="StoreA">
<input type="text" [(ngModel)]="StoreB">
</code>
<code> <input type="text" [(ngModel)]="Name" (ngModelChange)="updateOtherFields()">
<input type="text" [(ngModel)]="StoreA">
<input type="text" [(ngModel)]="StoreB">
</code>
<input type="text" [(ngModel)]="Name" (ngModelChange)="updateOtherFields()">
<input type="text" [(ngModel)]="StoreA">
<input type="text" [(ngModel)]="StoreB">
Expect output (textbox value)
|Mary|
|Spoon|
|Plate|