【问题标题】:Property 'zip' does not exist on type 'typeof Observable'. Angular 6“typeof Observable”类型上不存在属性“zip”。角 6
【发布时间】:2019-06-30 01:53:26
【问题描述】:

我正在使用 Angular 6 并阅读了有关管道的信息,但也没有获得任何正确的语法来编写 zip 和导入的 zip。
错误:属性“zip”不存在在“typeof Observable”类型上。

import { zip } from 'rxjs/operators';

callZipFunction(): void {
            Observable
            .zip( this.commonService.GetMethodA(), this.commonService.GetMethodB())
            .subscribe(([a,b])=>{
            console.log(a);
            console.log(b);
            });
        }

【问题讨论】:

  • 你想使用哪个版本的 rxjs?
  • "rxjs": "~6.3.3"
  • 然后尝试import { zip } from 'rxjs'; 并删除Observable.zip 前面的点...
  • 不客气。 :)

标签: angular typescript angular6


【解决方案1】:

尝试这样导入

import {Observable} from "rxjs/Observable";
import "rxjs/add/observable/zip";

Refrence

【讨论】:

    【解决方案2】:

    @dmcgrandle 感谢您解决问题

    import { zip  } from 'rxjs';
    
        callZipFunction(): void {
            zip( this.commonService.GetMethodA(), this.commonService.GetMethodB())
            .subscribe(([a,b])=>{
            console.log(a);
            console.log(b);
            });
        }
    

    【讨论】:

      【解决方案3】:

      如果你有这样的代码;

        let source$ = Observable.range(0, this.value).zip(
         Observable.timer(0, 1000),
         (x) => { return x }
        ).map(x => {
         return this.value - x
        });        
      

      添加;

          import "rxjs/add/operator/map";
          import "rxjs/add/operator/zip";
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-11-25
        • 2018-11-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-03-31
        • 1970-01-01
        相关资源
        最近更新 更多