简体   繁体   English

'void'类型上不存在属性'管道' Angular 9

[英]Property 'pipe' does not exist on type 'void' Angular 9

i create a function for stram audio in angular:我在 angular 中为 stram 音频创建了一个 function:

 private streamObservable(url) {
    new Observable(observer => {
      // Play audio
      this.audioObj.src = url;
      this.audioObj.load();
      this.audioObj.play();

      const handler = (event: Event) => {
        observer.next(event);
      };

      this.addEvents(this.audioObj, this.audioEvents, handler);
      return () => {
        // Stop Playing
        this.audioObj.pause();
        this.audioObj.currentTime = 0;
        // remove event listeners
        this.removeEvents(this.audioObj, this.audioEvents, handler);
      };
    });
  }

and when i need to using that function it show me error:当我需要使用该 function 时,它会显示错误:

function use: function 用途:

 playStream(url) {
    return this.streamObservable(url).pipe(takeUntil(this.stop$));
}

and show this error:并显示此错误:

Property 'pipe' does not exist on type 'void'.类型“void”上不存在属性“管道”。

whats the problem???how can i solve this problem???什么问题???我该如何解决这个问题???

You need to return the observable from the called function.您需要从被调用的 function 返回 observable。

Like - return new Observable (observer => { Like - return new Observable (observer => {

 private streamObservable(url) {
    return new Observable(observer => {
      // Play audio
      this.audioObj.src = url;
      this.audioObj.load();
      this.audioObj.play();

      const handler = (event: Event) => {
        observer.next(event);
      };

      this.addEvents(this.audioObj, this.audioEvents, handler);
      return () => {
        // Stop Playing
        this.audioObj.pause();
        this.audioObj.currentTime = 0;
        // remove event listeners
        this.removeEvents(this.audioObj, this.audioEvents, handler);
      };
    });
  }

The solution for me was a pretty simple mistake, in my case I was returning an observable but I wasn't calling the method properly.对我来说,解决方案是一个非常简单的错误,在我的情况下,我返回了一个 observable,但我没有正确调用该方法。 I was missing the () in the method call.我在方法调用中缺少()

Original Code原始代码

this.service.method.pipe().subscribe();

Fixed Code固定代码

this.service.method().pipe().subscribe();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 角度2中的类型'void'上不存在属性'subscribe' - Property 'subscribe' does not exist on type 'void' in angular 2 类型 void 上不存在属性 - Property does not exist on type void 在Angular2 +中,类型'()=> void'上不存在属性'nativeElement' - Property 'nativeElement' does not exist on type '() => void' in Angular2+ 类型'void'上不存在属性'sendEmailVerification' - Property 'sendEmailVerification' does not exist on type 'void' “void”类型上不存在属性“forEach” - Property 'forEach' does not exist on type 'void' 类型“void”SVELTE 上不存在属性“then” - property 'then' does not exist on type 'void' SVELTE Observable 类型上不存在属性管道 - Property pipe does not exist on type Observable 类型'void'上不存在属性'subscribe'。 Angular 2 asp.net核心 - Property 'subscribe' does not exist on type 'void'. Angular 2 asp.net core Angular。 TS2339:“无效”类型上不存在属性“订阅” - Angular. TS2339: Property 'subscribe' does not exist on type 'void' 在Angular 2 App中返回一个Observable,但仍然出现错误:“ void”类型不存在“属性“ subscribe” - Returning an Observable in Angular 2 App, but still getting error: "Property 'subscribe' does not exist on type 'void'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM