首页 > 解决方案 > 在订阅者Angular 8中停止循环

问题描述

我想知道根据订阅者的结果停止while循环的最佳方法是什么。该函数是异步的,因此break无效。我尝试了以下方式,但它永远不会更新this.output = false,所以循环是无限的。

getTesting(){
    while ( this.output == true ){      
      this.dataService.getThings().subscribe(res=> {
        if(res.length == 10){
          ...
          this.output = true
        }
        else{
          this.output = false
        }        
      })
    }
  }

标签: angulartypescriptloops

解决方案


推荐阅读