小编Maj*_*jiD的帖子

每 x 秒从 Observable 获取数据,使用开始和停止按钮

我有一个Observablex秒调用一次。

和两个名为StartStop 的按钮来控制 observable。

我想在用户按下停止按钮时停止进程并取消订阅,并在按下开始后每x秒开始获取数据

到目前为止我有:

public subscription: Subscription;
public isLoading: boolean = false;
public isStopped: boolean = true;

// Start Getting Data
getData() {
    this.isStopped = false;
    this.isLoading = true;

    this.subscription = this.proxy.InternetUserRwaits(model).pipe(
        repeatWhen(completed => {
            return completed.pipe(
                tap(_ => this.isLoading = false),
                delay(this.interval * 1000),
                tap(_ => this.isLoading = this.isStopped ? false : true),
            );
        }),
    )
    .subscribe(
        result => {
            this.isLoading = false; …
Run Code Online (Sandbox Code Playgroud)

rxjs angular

0
推荐指数
1
解决办法
403
查看次数

标签 统计

angular ×1

rxjs ×1