Angular2 RxJS getting 'Observable_1.Observable.fromEvent is not a function' error

﹥>﹥吖頭↗ 提交于 2019-11-29 23:11:31

Its definitly not needed to import all operators at once! You just imported fromEvent wrong. You could do it like this:

import {Observable} from 'rxjs/Observable';
import 'rxjs/add/observable/fromEvent';

EDIT: In addititon to what I already wrote: tree-shaking with the AoT-Compiler of angular removes unused code, based on what you import. If you just import some objects or functions from rxjs/rx, the compiler can't remove anything. Always import just, what you need!

Michael Oryl

The problem seemed to be that the import statement should look like this:

import {Observable} from 'rxjs/Rx';

Note that Observable is being brought in from rxjs/Rx instead of from rxjs/Observable. As @EricMartinez mentions, pulling it in this way will automagically get you all of the operators (like .map()).

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