hats
June 14, 2016, 5:16pm
1
I’m using the latest beta 8 and I’m getting this error when trying to load a json file:
property ‘map’ does not exist on type ‘Observable’
My code:
//ANGULAR/IONIC CORE IMPORTS
import {ionicBootstrap, Platform, MenuController, Nav} from 'ionic-angular';
import {Component, ViewChild} from '@angular/core';
import {Http, Response} from '@angular/http';
import {StatusBar} from 'ionic-native';
//FOUND THIS SUGGESTION ON ANOTHER FORUM
import {Observable} from 'rxjs/Observable';
import 'rxjs/add/operator/map';
class MainApp
{
@ViewChild(Nav) nav: Nav;
public rootPage: any = LoginView;
public HasSession: boolean = false;
public DataMenu: Object;
constructor(private platform: Platform, private menu: MenuController, private http: Http)
{
this.initializeApp();
}
private initializeApp()
{
this.platform.ready().then(() =>
{
StatusBar.styleDefault();
});
this.http.get('datamenu.json')
.map((res: Response) => res.json())
.subscribe(res => this.DataMenu = res);
}
}
Can someone help me?
Thank you
You can change to:
this.http.get(‘datamenu.json’)
.subscribe(res => {
this.DataMenu = res.json();
});
matheo
June 14, 2016, 8:13pm
3
You need to import that operator:
import 'rxjs/operators/map';
or adds all the operators to Observable (map, catch, etc) with:
import 'rxjs/Rx';
I don’t think lack of imports is the problem, because the following code works perfectly for me in a scratch project with no rx-related imports at all:
http.get('foo.json').map((rsp) => rsp.json())
.subscribe((foo) => {
console.log(foo);
});
hats
June 15, 2016, 9:27am
5
I added the suggested imports… but I’m still getting the error.
btw, i’m using Visual Studio 2015. Can be related to something with VS?
MauroB
June 15, 2016, 4:52pm
6
For this error in VS2015, there’s a github issue & workaround mentioned here:
opened 07:47PM - 08 May 16 UTC
closed 05:53AM - 20 May 16 UTC
Duplicate
Hi,
In visual studio, i got this error in every d.ts file under node_modules\rx… js\add\observable\ :
**Invalid module name in augmentation, module '../../Observable' cannot be found.**
example code: **declare module '../../Observable' {**
how to fix that please?
1 Like
hats
June 16, 2016, 10:02am
7
Thank you! That solved the problem…
I suspected from VS 2015 because I installed VS Code and there was no errors there.