【发布时间】:2021-03-03 22:57:33
【问题描述】:
我有一项显示穿着、信息和错误通知的服务。 有时通知来得很频繁。让我们说 20-30 在同一时间,我试图通过在特定时间间隔发生时取消订阅来避免这件事。
退订后就不能再订阅了。
const locationsSubscription = this.messageService
.getMessage()
.pipe(timeInterval(), tap(console.log))
.subscribe(message => {
if (message.interval < 500) {
locationsSubscription.unsubscribe();
}
else {
switch (message.type){
case MessageType.Info:
this.showInfo(message.text);
break;
case MessageType.Warning:
this.showWarning(message..text);
break;
case MessageType.Error:
this.showError(message.value);
break;
}
}
});
【问题讨论】:
-
为什么要退订?
-
因为有很多通知,不想全部显示
标签: angular rxjs subscription unsubscribe