如何从该示例中调用取消订阅方法?
var observable = Rx.Observable.create(function subscribe(observer) {
// Keep track of the interval resource
var intervalID = setInterval(() => {
observer.next('hi');
}, 1000);
// Provide a way of canceling and disposing the interval resource
return function unsubscribe() {
clearInterval(intervalID);
};
});
答案 0 :(得分:0)
你能这样尝试吗?
let subscription = observable.subscribe(sub=> {
// call unsubscribe
subscription.unsubscribe();
});