admin管理员组文章数量:1327683
i create a function for stram audio in angular :
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 use :
playStream(url) {
return this.streamObservable(url).pipe(takeUntil(this.stop$));
}
and show this error :
Property 'pipe' does not exist on type 'void'.
whats the problem ???how can i solve this problem ???
i create a function for stram audio in angular :
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 use :
playStream(url) {
return this.streamObservable(url).pipe(takeUntil(this.stop$));
}
and show this error :
Property 'pipe' does not exist on type 'void'.
whats the problem ???how can i solve this problem ???
Share Improve this question asked Aug 16, 2020 at 6:42 kianoush dortajkianoush dortaj 4519 silver badges28 bronze badges2 Answers
Reset to default 5You need to return the observable from the called function.
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. I was missing the ()
in the method call.
Original Code
this.service.method.pipe().subscribe();
Fixed Code
this.service.method().pipe().subscribe();
本文标签: javascriptProperty 39pipe39 does not exist on type 39void39 Angular 9Stack Overflow
版权声明:本文标题:javascript - Property 'pipe' does not exist on type 'void' Angular 9 - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742217744a2434877.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论