本文介绍了如何取消Angular2订阅的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
怎样才能取消Angular2订阅? RxJS似乎有Dispose方法,但我无法弄清楚如何访问它。所以,我有code可以访问一个EventEmitter并订阅它,就像这样:
How does one cancel a subscription in Angular2? RxJS seems to have a dispose method, but I can't figure out how to access it. So I have code that has access to an EventEmitter and subscribes to it, like this:
var mySubscription = someEventEmitter.subscribe(
(val) => {
console.log('Received:', val);
},
(err) => {
console.log('Received error:', err);
},
() => {
console.log('Completed');
}
);
如何使用 mySubscription
取消订阅?
推荐答案
您希望退订?
mySubscription.unsubscribe();
这篇关于如何取消Angular2订阅的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!