I organized my application in feature modules using @NgModule.
I want to use the module constructor to do some initialization needed for each module (e.g.: Registering for relevant events at a central notification module). Now, to handle specific events, the module has to push pages to the navigation controller. I am able to get references to any service or controller, but I cannot access the NavController in the module constructor.
Example:
@NgModule({
imports: [
IonicModule,
SharedModule,
NotificationModule
],
declarations: [
XXDetailsPage,
XXParticipantListPage,
],
entryComponents: [
XXDetailsPage,
XXParticipantListPage,
],
providers: [],
exports: []
})
export class XXModule {
constructor(
@Inject('NotificationProvider') notificationProvider: INotificationProvider,
navCtrl: NavController // <<<<<<<<<<<<<< not possible
) {
// register notification handlers
notificationProvider.registerNotificationInteractionHandler("xx.NewRequest", (notification: Notification) => {
navCtrl.push(XXDetailsPage, notification.data.xx);
navCtrl.push(XXParticipantListPage, notification.data.xx);
});
}
}
Now I’m looking for another way to get a reference to the NavController. In the docs, I found this hint: http://ionicframework.com/docs/v2/components/#navigating_from_root which explains why I cannot inject it here, but unfortunately I still have no idea how to get a reference.
Any ideas?
Alternatively, I could provide some kind of init() Method on the module which does the initialization, which I could call from the Root Module and pass the NavController as parameter. But how could I get a reference to the module object?