this.form = this.fb.group({
prop1: '',
prop2: ''
});
this.form.valueChanges.pipe(startWith(null), pairwise())
.subscribe(([prev, next]: [any, any]) => {
console.log('PREV2', prev);
console.log('NEXT2', next);
});
using this code I am able to get the previous value and current value. what I want is there any way to get which field is changed, prev value and current value.
like field changed name: prop1, prev value:"", current value: "next value"
Instead of subscribing to theFormGroup.valueChanges
observable, you could subscribe to the FormControl.valueChanges
observable.
See https://angular.io/api/forms/FormControl for the implementation.
This way you could have access to the control itself.
Maybe something like this?
Object.keys(this.form.controls).forEach(key => {
this.form.controls[key].valueChanges.pipe(startWith(null), pairwise())
.subscribe(([prev, next]: [any, any]) => {
console.log(key) // your FormControl Identifier
console.log('PREV2', prev);
console.log('NEXT2', next);
});
});