How can I watch just 2 fields of an Angular ReactiveForm? I have a form like the following:
this.filter = this.fb.group({
text: ['', []],
bankCountry: ['', []],
bankCity: ['', []]
});
How can I watch for changes related to just the last 2 fields?
Two ways:
1st, using combineLatest:
http://reactivex.io/rxjs/class/es6/Observable.js~Observable.html#static-method-combineLatest
Observable.combineLatest( this.text.valueChanges, this.bankCountry.valueChanges ).subscribe(respArr => {
console.log(respArr); //this is array with responses from both observables
});
2nd, using filter:
http://reactivex.io/rxjs/class/es6/Observable.js~Observable.html#instance-method-filter
this.filter.valueChanges.filter((val) => /*filter predicate returning boolean*/).subscribe(val => {
console.log(val);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With