Property 'subscribe' does not exist on type 'Promise<Client>'. ngx-soap package

Viewed 1614

I am trying to get a soap request with Angular 6 using the ngx-soap package. I have a service to handle the api like so:

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

@Injectable()
export class ApiService {

client: Client;

  constructor(
    private soap: NgxSoapService
  ) {
    this.soap.createClient('assets/wsdl/auth/auth.wsdl').subscribe(client => this.client = client);
  }
}

Although and even though this is the exact example on the package page I get the following error:

[ts] Property 'subscribe' does not exist on type 'Promise<Client>'.

I know I can use the then but shouldn't it be possible to subscribe using this package?

1 Answers

You need to convert the promise to an observable and then you can subscribe.

For RxJs v6 change your code to:

import { from } from 'rxjs'

const promise = this.soap.createClient('assets/wsdl/auth/auth.wsdl')
from(promise).subscribe(client => this.client = client)

For RxJs v5:

import 'rxjs/add/observable/fromPromise'
import { Observable } from 'rxjs/Observable'

const promise = this.soap.createClient('assets/wsdl/auth/auth.wsdl')
Observable.fromPromise(promise).subscribe(client => this.client = client)
Related