in my cordova app i catch the onResume
event in the main.ts
file, and there i need, under certain conditions, to navigate to home screen of my app. For that i'am trying to inject the RouterModule
into this application entry point file, but have problem with this injection.
i successfully injected the HttpClientModule
according to this explanation, but i can't inject the RouterModule
in the same way.
here is my main.ts
file:
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app/app.module';
import { Router, RouterModule } from '@angular/router';
platformBrowserDynamic().bootstrapModule(AppModule)
.catch(err => console.log(err));
document.addEventListener('deviceready', onDeviceReady, false);
let onDeviceReady = () => {
document.addEventListener("resume", onResume, false);
}
let onResume = () => {
...
// here i need the Router and use it like: router.navigate(['home'])
...
}
and here is my router defined in the app.module.ts
:
import { RouterModule } from '@angular/router';
const routes: Routes = [
{ path: 'home', component: HomeComponent},
{ path: '', redirectTo: '/home', pathMatch: 'full' },
{ path: '**', component: PageNotFaundComponent }
];
@NgModule({
...
imports: [RouterModule.forRoot(routes)]
...
)}
export class AppModule { }
and in any component or service in my app i can use the Router
like that:
import { Router } from '@angular/router';
import { Injectable, forwardRef, Inject } from '@angular/core';
@Injectable()
export class DemoService {
constructor(private router: Router) { }
NavigateHome() {
this.router.navigate(['/home']);
}
}
so, is there a way to get that ability of Router navigation in the main.ts
file?
alternatively, is there a better location for catching this device events in an angular application, so i can easily use the Router
?
Thanks!