【发布时间】:2017-03-07 05:55:41
【问题描述】:
我正在尝试使用 ionic-angular 中的 Publish 和 Subscribe。
subscribe.js
this.events.subscribe('done:eventA', (userEventData) => {
//Perform some operations
this.startEventB();
this.events.unsubscribe('done:eventA'); <---
}
this.events.subscribe('done:eventB', (userEventData) => {
//Perform some operations
this.startEventA();
}
this.events.subscribe('done:eventA', (userEventData) => {
//Perform some operations
this.startEventC();
}
startEventB(){
this.events.publish('done:eventB', data);
}
startEventA(){
this.events.publish('done:eventA', data);
}
第一次事件 A 发布我要执行 startEventB()
第二次时间事件 A 是发布我想执行 startEventC() 所以我尝试从第一部分开始 unsubscribe。
但是当我unsubscribe 时,我所有的订阅都消失了。
我可以知道订阅和取消订阅事件的好方法吗?
【问题讨论】:
标签: javascript angularjs ionic-framework ionic2 dom-events