代码之家  ›  专栏  ›  技术社区  ›  JoaoFilipeClementeMartins

类型“Promise<Client>”上不存在属性“subscribe”。ngx-soap包

  •  1
  • JoaoFilipeClementeMartins  · 技术社区  · 6 年前

    ngx-soap 包裹。

    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);
      }
    }
    

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

    我知道我可以使用,但不应该有可能订阅使用这个包?

    1 回复  |  直到 6 年前
        1
  •  5
  •   danday74    6 年前

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

    对于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)