【发布时间】:2020-06-01 01:35:22
【问题描述】:
自从 Ionic 5 推出后,我决定尝试一下。 我了解到他们现在使用的是 Oberservables 而不是事件。 我的代码中有以下事件:
在我的构造函数中这样订阅:
this.events.subscribe('go-to-slide', (tab, id) => {
this.currentID = id;
if (id === 0) {
this.showLeftButton = false;
}
// if data has already been loaded
if (this.dataLoadedFlag === true) {
// from tile
if (this.globalVariableService.comesFromTileClick === true) {
if (this.globalVariableService.languageChanged === true) {
this.languageChanged = false;
this.slidesComponent.slides.slideTo(id, 0);
this.getSectorTitlesAndColours();
this.dataLoadedFlag = true;
this.updateHeader(id);
} else if (this.globalVariableService.languageChanged === false) {
this.updateHeader(id);
}
} else if (this.globalVariableService.comesFromTileClick === false) {
}
} else if (this.dataLoadedFlag === false) {
if (this.globalVariableService.comesFromTileClick === true) {
this.slidesComponent.slides.slideTo(id, 0);
this.getSectorTitlesAndColours();
this.dataLoadedFlag = true;
this.updateHeader(id);
} else if (this.globalVariableService.comesFromTileClick === false) {
this.getSectorTitlesAndColours();
this.showRightButton = true;
this.dataLoadedFlag = true;
this.updateHeader(0);
}
}
const tempGlobalVariableService = this.globalVariableService;
// tslint:disable-next-line: only-arrow-functions
setTimeout(function() {
tempGlobalVariableService.comesFromTileClick = false;
}, 500);
});
}
并在不同的组件/方法中像这样发布事件:
this.events.publish('go-to-slide', 1, 1);
我尝试了不同的方法来将此代码更改为可观察的,但我似乎找不到正确的方法。
任何人已经尝试过并且可以帮助我吗? 谢谢
【问题讨论】:
标签: javascript angular events observable ionic5