Cannot resolve toPromise in an angular webservice

Ms01

I am trying to create a very simple angular service:

import { Http, Response } from '@angular/http';
import 'rxjs/add/operator/toPromise';

export class Webservice {

  constructor(private http: Http) {

  }

  getMessages() {
    return this.http.get('http://localhost:63962/api/someshittyendpoint').toPromise();
  }
}

Whatever I do, I get the following Module not found: Error: Can't resolve 'rxjs/add/operator/toPromise'.

I have installed rxjs-compat and verified that the module actually is on the path. I don't understand what's wrong?

Thanks in advance!

martin

toPromise is not an operator. It's a method on the Observable class which means you don't have to import it:

See the source code: https://github.com/ReactiveX/rxjs/blob/5.5.11/src/Observable.ts#L332-L354

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Angular Http - toPromise or subscribe

Angular CanActivated: canActivated return toPromise

Apache CXF WS Security WebService from NET Client - Cannot resolve KeyInfo for unwrapping key

Angular2 - Replacing toPromise on a Service Call

The right way to use toPromise in angular 6

Getting Post angular 2 toPromise HTTP

Angular 8: Using HttpClient.get.toPromise

How to handle .toPromise() deprecation with RXJS and Angular 13

Cannot install Webservice::InterMine

Jenkins building angular project gets Cannot read property 'resolve' of undefined

Angular6 - cannot resolve 'fs' in selenium-webdriver\lib

Angular 2 error: Cannot resolve all parameters for 'RouteParams'

ng test "Cannot resolve 'fs'" after updating to Angular 8

Angular 2 Di not working - cannot resolve all parameters for

Angular 2 HTTP "Cannot resolve all parameters for 'AppService'"

How to resolve resource is not available in Restful WebService

Cannot resolve @angular/http in node_modules\@angular\platform-server\bundles in angular 5 aspnet prerendering

Angular2 - TypeError: this.http.get(...).toPromise is not a function

Angular/rxjs: Why don't I have to import toPromise anymore?

Angular 2 / 4 toPromise works but I am having trouble with Observables

angular Firestore: Observable.toPromise() versus Observalble.firstValueFrom();

Angular 7 HttpClient: ToPromise does not work with put request

Cannot call webservice exposed by Mule

WebService WCF - Cannot obtain metadata

How to Resolve 'Cannot Find Module' Error in Angular for 'angular2-signaturepad/signature-pad'?

Angular Sending an URL parm to a webservice

Getting Angular to work with a Moodle webservice

Cannot resolve symbol 'Enum'

cannot resolve symbol 'servlet'