node_modules / rxjs / Rx没有导出的成员“合并”

时间:2018-07-01 05:59:47

标签: angular rxjs rxjs5

我的组件:

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'

1 个答案:

答案 0 :(得分:2)

merge可以用作staticinstance方法。

用于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))
        );

Live Demo