angular - 在订阅者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
}
})
}
}
解决方案
推荐阅读
- angular - 如何通过 Injector.create 注入一个类的数组
- java - 解决 Android SDK 错误:Handler.getLooper() 清除线程中断状态
- python - 凭经验得出轴关系时,如何在matplotlib图中配置次轴?
- rabbitmq - RabbitMQ 突然停止发布/消费消息
- python - 脚本Python中的进度条
- r - 错误:在 R 中运行绘图采样时,C 堆栈使用 15925344 太接近限制
- excel - 自定义类型来存储和输出数据
- javascript - 在javascript中访问另一个对象内的对象
- filter - 使用管道和过滤器过滤可观察的 number[]
- postgresql - 在 PostgreSQL 中获取不带扩展名的 windows 文件名