There were a lot of questions about the fact that “map is not a function”, but almost all simply did not import the rxjs library.
In my case, I am importing, but the error still exists.
I work with Ionic 2, and here is what my package.json dependencies look like:
"dependencies": { "@angular/common": "2.0.0", "@angular/compiler": "2.0.0", "@angular/compiler-cli": "0.6.2", "@angular/core": "2.0.0", "@angular/forms": "2.0.0", "@angular/http": "2.0.0", "@angular/platform-browser": "2.0.0", "@angular/platform-browser-dynamic": "2.0.0", "@angular/platform-server": "2.0.0", "@ionic/storage": "1.0.3", "ionic-angular": "2.0.0-rc.1", "ionic-native": "2.2.3", "ionicons": "3.0.0", "rxjs": "5.0.0-beta.12" }
So this is how I create my service:
import { Injectable } from '@angular/core'; import { Http, Headers, RequestOptions, Response } from '@angular/http'; import { Observable } from 'rxjs'; import 'rxjs/add/operator/map'; @Injectable() export class LoginService { constructor(private http: Http) { } private dataUrl = '/node'; getData() : any { this.http.get(this.dataUrl) .map(response => response.json()) .subscribe(result => console.log(result)); } }
I also tried reinstalling the rxjs module, but still did not succeed. Maybe this is incompatible with ionic 2 or the current version of angular?
What do the guys think?
Greetings
Andrey
angular rxjs ionic2
Andrej Tihonov
source share