Search code examples
angularangular2-router3

Bootstrap at least one component before injecting Router


I am trying to implement Auth Service in final release of Angular 2, I had just two component : Login Component and Admin Component and I am guardin admin Component but results in following error, since I have no choice about the component to load earlier than admin, Is there any workout for this issue ??

zone.js:344 Unhandled Promise rejection: Bootstrap at least one component before injecting Router. ; Zone: <root> ; Task: Promise.then ; Value: Error: Bootstrap at least one component before injecting Router.(…) Error: Bootstrap at least one component before injecting Router.
at setupRouter (http://localhost:3000/scripts/@angular/router//bundles/router.umd.min.js:13:18707)
at NgModuleInjector.get (AppModule.ngfactory.js:372:57)
at NgModuleInjector.AppModuleInjector.createInternal (AppModule.ngfactory.js:561:64)
at NgModuleInjector.create (http://localhost:3000/scripts/@angular/core//bundles/core.umd.min.js:30:1140)
at NgModuleFactory.create (http://localhost:3000/scripts/@angular/core//bundles/core.umd.min.js:30:673)
at eval (http://localhost:3000/scripts/@angular/core//bundles/core.umd.min.js:29:25106)
at ZoneDelegate.invoke (http://localhost:3000/scripts/zone.js/dist/zone.js:192:28)
at Object.onInvoke (http://localhost:3000/scripts/@angular/core//bundles/core.umd.min.js:29:16609)
at ZoneDelegate.invoke (http://localhost:3000/scripts/zone.js/dist/zone.js:191:34)
at Zone.run (http://localhost:3000/scripts/zone.js/dist/zone.js:85:43)consoleError @ zone.js:344_loop_1 @ zone.js:371drainMicroTaskQueue @ zone.js:375ZoneTask.invoke @ zone.js:297

zone.js:346 Error: Uncaught (in promise): Error: Bootstrap at least one component before injecting Router.(…)


Solution

  • Solved it by removing ngOnInit() method on AuthService