Reputation: 6852
I have some fields in reactive forms that I have to check if values have changed. I know how to check if value have changed on one field like this
this.form.controls['phone'].valueChanges.subscribe(
data => console.log('form changes', data)
);
The problem I have is that I need to check two or more fields, e.g. phone and address.
Upvotes: 1
Views: 2026
Reputation: 3593
You can merge observables, but it merges into a single observable, i.e.
import { merge } from 'rxjs';
merge(
this.form.controls['phone'].valueChanges,
this.form.controls['address'].valueChanges
).subscribe(console.log)
alternatively you can use combineLatest. Which will emit the latest value from each observable. I think this is what you need.
import { combineLatest } from 'rxjs';
combineLatest(
this.form.controls['phone'].valueChanges,
this.form.controls['address'].valueChanges
).subscribe((phone, address) => {
// do something
})
Upvotes: 8