我的组件:
import {Observable, Subject , merge} from 'rxjs';
import {debounceTime, distinctUntilChanged, filter, map} from 'rxjs/operators';
focus$ = new Subject<string>();
click$ = new Subject<string>();
search = (text$: Observable<string>) => {
const debouncedText$ = text$.pipe(debounceTime(200), distinctUntilChanged());
const clicksWithClosedPopup$ = this.click$.pipe(filter(() => !this.instance.isPopupOpen()));
const inputFocus$ = this.focus$;
return merge(debouncedText$, inputFocus$, clicksWithClosedPopup$).pipe(
map(term => (term === '' ? states
: states.filter(v => v.toLowerCase().indexOf(term.toLowerCase()) > -1)).slice(0, 10))
);
}
版本:
"rxjs": "^5.5.6",
"@angular/cli": "1.3.2",
"@angular/compiler-cli": "^4.2.4"
我收到错误消息:
node_modules / rxjs / Rx“'没有导出的成员'merge'
答案 0 :(得分:2)
merge
可以用作static
或instance
方法。
用于static
方法使用
import { merge } from 'rxjs/observable/merge';
return merge(debouncedText$, inputFocus$, clicksWithClosedPopup$).pipe(
map(term => (term === '' ? states
: states.filter(v => v.toLowerCase().indexOf(term.toLowerCase()) > -1)).slice(0, 10))
);
对于instance
方法,请使用
import { merge } from 'rxjs/operators';
return Observable.merge(debouncedText$, inputFocus$, clicksWithClosedPopup$).pipe(
map(term => (term === '' ? states
: states.filter(v => v.toLowerCase().indexOf(term.toLowerCase()) > -1)).slice(0, 10))
);