自从 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);
我尝试了不同的方法来将此代码更改为可观察的,但我似乎找不到正确的方法。
有人已经尝试过这个并且可以帮助我吗?谢谢