我想在10000秒内停止某个功能,但这不适用于angular:
setTimeout(() => {
this
.ngZone
.run(() => {
if (device.name.includes('DeviceName')) {
this.connectToDevice(device)
}
});
}, 10000, console.log('not found'));
这将在10000之后启动该功能,但是我需要在10000秒后停止该功能并显示一条消息。
答案 0 :(得分:5)
您可以将管道与rxjs中的超时一起使用
从'rxjs / operators'导入{超时};
示例:
your_subscription
.pipe(timeout(10000)) // closed after 10 seconds
.subscribe((result) => {
// do stuff
});