How to get “Observable.of([]);” to work?

Deadly 提交于 2019-11-27 07:46:42

问题


What is the correct expression and import for Observable.of([]);.

import { of } from 'rxjs'; does not work for me.


回答1:


Since RxJS 6 you should import all "creation" observables directly from 'rxjs' (assuming you have path maps set when bundling your app).

More detailed explanation: https://github.com/ReactiveX/rxjs/blob/master/MIGRATION.md#import-paths

import { of } from 'rxjs';

of(1).subscribe(console.log);

See demo: https://stackblitz.com/edit/typescript-e3lxkb?file=index.ts




回答2:


No need to use Observable.of(T) Instead you can use the below syntax in the rxjs 6.3.3

return new Observable<AppUser>();


来源:https://stackoverflow.com/questions/50218784/how-to-get-observable-of-to-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!