如何只观看Angular ReactiveForm的2个字段? 我的表格如下:
this.filter = this.fb.group({
text: ['', []],
bankCountry: ['', []],
bankCity: ['', []]
});
如何查看与最后两个字段相关的更改?
答案 0 :(得分:1)
两种方式:
1,使用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
});
2,使用过滤器:
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);
});