Home > OS >  Want to set the values to form component of template driven form in angular?
Want to set the values to form component of template driven form in angular?

Time:11-27

I have a 2 components add-items and view-items. view-items is my parent component and add-item is my child component.

In view-items component i have table and its data. There is a Edit button in my each row. So, when user clicks on edit button. i am sending that row values to add-items component. but, i am unable to set those values in form and unable to update in table with specified row. can anyone help me here?

Thanks in advance!

CodePudding user response:

You have to implement ngOnChanges and copy all properties to StudentFormData.

export class AddItemsComponent implements OnInit, OnChanges{

  :
  
  ngOnChanges(changes: SimpleChanges): void {
    this.StudentFormData.name = this.item.name;
    this.StudentFormData.division = this.item.division;
    this.StudentFormData.gender = this.item.gender;
  }

}
  • Related