Angular and RxJS imports

后端 未结 3 1558
走了就别回头了
走了就别回头了 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:51

    Starting from WebStorm 2016.3 (I believe), you have an option to blacklist certain imports. Editor > Code Style > StypeScript

    Do not import exactly from: [rxjs]
    

    Additionally, there is a flag available in tslint to prohibit global imports:

    {
      "rules": {
        "import-blacklist": [true, "rxjs"]
      }
    }
    
    0 讨论(0)
  • 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.

    0 讨论(0)
  • You can use all operators by using this:

    import * as Rx from "rxjs/Rx";
    
    Rx.Observable.of(1,2,3,4,5);
    
    0 讨论(0)
提交回复
热议问题