相关疑难解决方法(0)

如何在RxJS中"等待"两个可观察对象

在我的应用程序中我有类似的东西:

this._personService.getName(id)
      .concat(this._documentService.getDocument())
      .subscribe((response) => {
                  console.log(response)
                  this.showForm()
       });

 //Output: 
 // [getnameResult]
 // [getDocumentResult]

 // I want:
 // [getnameResult][getDocumentResult]
Run Code Online (Sandbox Code Playgroud)

然后我得到两个分开的结果,第一个_personService然后是_documentService.如何在调用之前等待两个结果this.showForm()然后操纵每个结果.

javascript reactive-programming rxjs angular

51
推荐指数
4
解决办法
4万
查看次数

combineLatest弃用了静态combineLatest

使用后运行rxjs迁移工具

rxjs-5-to-6-migrate -p src/tsconfig.app.json

我现在得到一个linting错误:

combineLatest已弃用:不赞成使用static combineLatest.

在运行迁移命令之前,这是我的代码:

this.store.combineLatest(
        this.store.select(lang.getCurrent),
        this.store.select(lang.getCurrentLocale)
    ).subscribe(([state, currentLang, locale]) => {
        this._language = session.language === currentLang ? '' : currentLang;
        this._locale = session.locale === locale ? '' : locale;
    });
Run Code Online (Sandbox Code Playgroud)

运行迁移命令后的代码:(当前显示linting错误)

import {map, combineLatest} from 'rxjs/operators';
this.store.combineLatest(
        this.store.select(lang.getCurrent),
        this.store.select(lang.getCurrentLocale)
    ).subscribe(([state, currentLang, locale]) => {
        this._language = session.language === currentLang ? '' : currentLang;
        this._locale = session.locale === locale ? '' : locale;
    });
Run Code Online (Sandbox Code Playgroud)

问题在这个stackoverflow问题中被问到,但它不够具体:Angular 6 ng lint重复错误和警告,combineLatest已被弃用 .

rxjs rxjs6

32
推荐指数
4
解决办法
2万
查看次数

标签 统计

rxjs ×2

angular ×1

javascript ×1

reactive-programming ×1

rxjs6 ×1