20

在 JsBin 中,我在 Firefox 和 Chrome 中收到错误“Rx.Observable.just 不是函数”。JsBin 示例:http ://jsbin.com/vunuta/edit?html,js,console

HTML:

script src="https://npmcdn.com/@reactivex/rxjs@5.0.0-beta.7/dist/global/Rx.umd.js">

打字稿:

Rx.Observable.from ([1,2,3]).subscribe(x => console.log(x)); // Work
Rx.Observable.just (99).subscribe(x => console.log(x)); // Fail
Rx.Observable.return (99).subscribe(x => console.log(x)); // Fail

发送

4

2 回答 2

36

Rx.Observable.just()v5 中不再提供。使用Rx.Observable.of(). https://github.com/ReactiveX/rxjs/blob/master/MIGRATION.md

于 2016-09-10T14:27:23.237 回答
4

rxjs v6 的更新

是的,使用of而不是just. ofrxjs v5 和 rxjs v6 之间的导入和使用发生了变化。

对于 rxjs v6,使用of如下示例代码:

import { of } from "rxjs";

let source$ = fromPromise(getPostById(1)).pipe(
  flatMap(post => {
    return hydrateAuthor(post);
  }),
  catchError(error => of(`Caught error: ${error}`))
);
于 2019-05-05T11:35:57.853 回答