Angular and RxJS imports

后端 未结 3 1590
走了就别回头了
走了就别回头了 2021-01-02 03:33

I\'ve always known to import my Observable operators separately to limit the load times. However I\'ve noticed something today that I hope someone could please

3条回答
  •  误落风尘
    2021-01-02 03:52

    Why not have a file(ex: rxjs-extensions.ts) with your required rxjs observable class extensions and operators?

    // Observable class extensions
    import 'rxjs/add/observable/throw';
    
    // Observable operators
    import 'rxjs/add/operator/do';
    import 'rxjs/add/operator/filter';
    import 'rxjs/add/operator/map';
    

    And then in your main module (ex app.module.ts) import from this file:

    import './rxjs-extensions';
    

    And in your main component (ex: app.component.ts) just import Observavle:

    import { Observable } from 'rxjs/Rx';
    

    This is how it is covered on the main angular tutorial.

提交回复
热议问题