1

I am very new in Angular2/4 and I have some problem trying to follow this tutorial related to PrimeNG:

https://www.primefaces.org/primeng/#/schedule

I created the EventService class into a file in my prohject, in this way:

import {Injectable} from '@angular/core';
import {Http} from '@angular/http';

@Injectable()
export class EventService {

  constructor(private http: Http) {}

  getEvents() {
    return this.http.get('showcase/resources/data/scheduleevents.json')
      .toPromise()
      .then(res => <any[]> res.json().data)
      .then(data => { return data; });
  }
}

The problem is that WebStorm give me an error on the toPromise() method, it says:

Error:(11, 8) TS2339:Property 'toPromise' does not exist on type 'Observable<Response>'.

Why? What it means? What is the problem? How can I try to fix it?

Antikhippe
  • 6,316
  • 2
  • 28
  • 43
AndreaNobili
  • 40,955
  • 107
  • 324
  • 596
  • 1
    Possible duplicate of [Property 'toPromise' does not exist on type 'Observable'](https://stackoverflow.com/questions/38090989/property-topromise-does-not-exist-on-type-observableresponse) – AT82 Aug 12 '17 at 08:15
  • 1
    The amount of time you put on writing this question, you could have perhaps just googled the error message and found an answer? ;) – AT82 Aug 12 '17 at 08:18

1 Answers1

2

You need to import the operator like this:

import 'rxjs/add/operator/toPromise';
Sajeetharan
  • 216,225
  • 63
  • 350
  • 396