I am trying to access web api methods from Angular 2 application, i am able to get the records using web api. But the problem is, service.ts file showing Property 'map' does not exist on type 'Observable' error.
Sample Code:
import { Injectable } from '@angular/core';
import { Http } from '@angular/http';
import { Observable } from 'rxjs/Observable';
import 'rxjs/Rx';
@Injectable()
export class ContactServices
{
private url = 'http://localhost:51498/api/test/';
constructor(private http: Http) { }
getContacts():Observable<Object[]> {
return this.http.get(this.url + 'GetContacts')
.map(response => response.json())
.catch(error => {
console.log(error);
return Observable.throw(error);
});
}
getContactById(id: number) {
return this.http.get(this.url + 'GetContactList/' + id)
.map(response => <Contact[]>response.json())
.catch(error => {
console.log(error);
return Observable.throw(error);
});
}
}
export class Contact {
Id: number;
Name: string;
Details: string;
}
I am using below versions,
- webpack 2.2.1
- angular 2.4.9
- node 6.10.0
- npm 4.1.2
- typescript 2.2.1