2 回答

TA貢獻1846條經驗 獲得超7個贊
原來使用以下方法很簡單
const curTime$ = videoStreams.currentTime$.pipe(
throttle(() => interval(10000))
);
它不是每三分之一秒左右返回一次玩家的位置,而是通過限制它返回時間點(我分配給它的)的值。

TA貢獻1779條經驗 獲得超6個贊
使用switchMap替代
“switchMap 和其他扁平化操作符之間的主要區別在于取消效果。在每次發射時,前一個內部可觀察對象(您提供的函數的結果)被取消并訂閱新的可觀察對象?!遍喿x更多關于 switchMap 的內容
import { Component } from '@angular/core';
import { interval,of } from 'rxjs';
import { flatMap,switchMap } from 'rxjs/operators';
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: [ './app.component.css' ]
})
export class AppComponent {
name = 'Angular';
currentTime$ = of(1,2,3,4,5,6,7,8)
ngOnInit() {
const int = interval(5000);
const subscription = int
.pipe(switchMap(() => this.currentTime$ ))
.subscribe(val => console.log("TIME", val));
}
}
添加回答
舉報