3

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
    Author of this package removed observable from createClient in favor of promise https://github.com/lula/ngx-soap/commit/d7284a557259452568b9ccb7e47bb70a60e6d2f5#diff-74047854f5c6513630fb6857f2be51c9 It should be possible to subscribe just take a look at https://stackoverflow.com/questions/39319279/convert-promise-to-observable – yurzui Sep 07 '18 at 16:44

1 Answers1

5

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)
danday74
  • 52,471
  • 49
  • 232
  • 283