mergeMap在类型observable上不存在

时间:2018-05-02 15:22:37

标签: typescript rxjs reactivex rxjs6

我正在mergeMap中使用rxjs6,我收到此错误:

Property 'mergeMap' does not exist on type 'Observable<{}>'

我已经尝试了import 'rxjs/add/operator/mergeMap';但它无效。

我做错了什么?

import {from, Observable} from 'rxjs';

export class Test {

    public doSomething(): Observable<any> {
        return from(...).mergeMap();
    }

}

4 个答案:

答案 0 :(得分:13)

这是正确的,&#34;补丁&#34;自RxJS 6以来,已经删除了运算符的样式。您应该更好地更新代码以仅使用&#34; pipeable&#34;运营商或安装it('should set up the subscription for saving', fakeAsync(() => { // Arrange component.type = 'full'; // START ********* MOVE THIS BLOCK UP mockedEditService.type.subscribe(type => { expect(type).toEqual(component.type); }); // END ********* MOVE THIS BLOCK UP // Act component.ngOnInit(); fixture.detectChanges(); mockedEditService.saveSelection.next(); })); 包,提供与RxJS 5的向后兼容性。

有关详细说明,请参阅官方文档:https://github.com/ReactiveX/rxjs/blob/master/docs_app/content/guide/v6/migration.md

......更具体地说,这部分:https://github.com/ReactiveX/rxjs/blob/master/docs_app/content/guide/v6/migration.md#backwards-compatibility

答案 1 :(得分:6)

感谢@martin给出的答案,我能够使用pipe中的新rxjs6操作。这是我的工作代码。

import {from, Observable} from 'rxjs';
import {mergeMap} from 'rxjs/operators';

export class Test {

    public doSomething(): Observable<any> {
        return from(...).pipe(mergeMap(...));
    }

}

答案 2 :(得分:3)

导入各个运算符,然后使用管道而不是链接。

{{1}}

来源:https://auth0.com/blog/whats-new-in-rxjs-6/

答案 3 :(得分:0)

组件HTML就像这样

public static void main(String args[]) {
    // The default port number.
    int portNumber = 8888;
    if (args.length < 1) {
        System.out.println("Chat server is up on " + portNumber);
    } else {
        portNumber = Integer.valueOf(args[0]).intValue();
        System.out.println("Chat server is up on " + portNumber);
    }
   }

导入所需功能

<input type="text" placeholder="input first" id="input1">
<input type="text" id="input2" placeholder="input second">
<span></span>