Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular reactive forms key changes detection

Given valueChanges listener with Angular Reactive Forms

this.companyForm.valueChanges.subscribe((value) => {
  console.log('setChangesListener value', value);
});

How do I find which field was changed exactly?

like image 425
Danil T Avatar asked Mar 29 '26 23:03

Danil T


1 Answers

There's no way to see which field changed from the top level form subscription.


However, you can individually subscribe to form controls and that way you know exactly which field changed:

Object.entries(this.formGroup.controls).forEach(value => {
  const [key, control] = value;
  control.valueChanges.subscribe(
    (val) => {
      console.log(key, val);
    },
  );
});
like image 170
Denes Papp Avatar answered Apr 01 '26 08:04

Denes Papp