jkuri / angular-rollup-starter

Angular2 & Rollup.js including AoT and Universal Prerendering
MIT License
32 stars 9 forks source link

How to include rxjs map operator in vendor.ts ? #2

Closed tekix closed 7 years ago

tekix commented 7 years ago

In webpack I can use the following code to include the rxjs map operator:

// vendor.ts

import 'rxjs/add/operator/map';

Is there any solution to include the rxjs operator in one place, so no need to import the operator in every file that uses it?

jkuri commented 7 years ago

Will check into this and come back with the answer.

jkuri commented 7 years ago

@itryan it does work for me without including rxjs/add/operator/map at all. Can you try the new version?

tekix commented 7 years ago

Thanks @jkuri , I moved the import 'rxjs/add/operator/map' to main.ts or /src/app/app.module.ts and now it works.

When putting it in vendor.ts it compiled successfully but got run time error if trying to use the map function

TypeError: this.http.get(...).map is not a function ...
// DemoComponent.ts

export class DemoComponent {
  constructor(private http: Http) {
  }

  // ...

  getData() {    
    return this.http.get(this.url).map(rspn => {
      let data = rspn.json().data;
      return data;
    })
    .subscribe(data => {
      // ...
    });
  }
}
jkuri commented 7 years ago

I have for example imported import { Observable } from 'rxjs' and works, looks like it just need to be included somewhere in source files or main.ts. Closing.