[英]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.