I searched previous threads asking about this error message. From what I can find there are two documented causes for this error message.
Missing
import 'rxjs/add/operator/toPromise'orimport 'import 'rxjs/add/operator/map'Error with Visual Studio (which I am not using).
This is the code in question
import { Injectable } from '@angular/core';
import { Headers, Http } from '@angular/http';
import {Observable} from 'rxjs/Rx';
import 'rxjs/add/operator/toPromise';
import 'rxjs/add/operator/map';
import { Event } from './event';
@Injectable()
export class EventService {
private eventsUrl = 'api/events'; // URL to web api
private headers = new Headers({'Content-Type': 'application/json'});
constructor(private http: Http) { }
getEvents(): Promise<Event[]> {
return this.http.get(this.eventsUrl)
.toPromise()
.then(response => response.json().data as Event[])
.catch(this.handleError);
}
}
The code above gives me the error Property 'toPromise' does not exist on type 'Observable<Response>'
EDIT: Thanks to @estus I found out that I installed one of the packages incorrectly. The package has its own node_modules that also had rxjs resulting in duplicates rxjs inside the project.