1

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.(…)

Sandeep
  • 121
  • 10
  • I think the problem is that you are not using any modules for your application. The latest version for angular 2 uses the process of creating modules for resolving all the dependencies of your application. What version of angular 2 are you using? – Abhinandan Sep 15 '16 at 18:09
  • I have upgraded to Final release 2.0 yesterday, but the issue was there since the RC 5 . I have implemented the Module for admin and placed all other module under it . It works fine without the AUTH Guard Service but gives the error once it is used – Sandeep Sep 16 '16 at 05:22

1 Answers1

4

Solved it by removing ngOnInit() method on AuthService

Sandeep
  • 121
  • 10
  • Actually I was calling the api call to check the loggedIn status on ngOnInit() lifecycle method which was causing the issue for me , when I removed it, that worked, but May be now in V2.1.0 beta the issue have been fixed in router – Sandeep Oct 10 '16 at 08:58
  • Lifecycle events are for components and directives? Putting an ngOnInit() in a service could well cause unexpected behaviour – Lee.Winter Dec 07 '16 at 20:07