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

后端 未结 2 1380
半阙折子戏
半阙折子戏 2020-12-24 04:49

I\'m using AngularJS 2 Beta 0 and I\'m trying to create an RxJS Observable from an event on a window object. I believe I know the formula for capturing the event as an Obse

2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-24 05:36

    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!

提交回复
热议问题