angular: Router: Services needing the Router service fail if OnDestroy is implemented

I’m submitting a … (check one with “x”)

[x] bug report => search github for a similar issue or PR before submitting
[ ] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior

Services that implement the OnDestroy interface that are included in the root NgModule providers are automatically instantiated. If the service injects the Router, it throws an error.

Error: Bootstrap at least one component before injecting Router

Expected/desired behavior

Services injecting the router that implement the OnDestroy interface are instantiated without error.

Reproduction of the problem If the current behavior is a bug or you can illustrate your feature request better with an example, please provide the steps to reproduce and if possible a minimal demo of the problem via https://plnkr.co or similar (you can use this template as a starting point: http://plnkr.co/edit/tpl:AvJOMERrnz94ekVua0u5).

http://plnkr.co/edit/JQVPXQt62G2W56S84R5R?p=preview

What is the expected behavior?

What is the motivation / use case for changing the behavior?

Please tell us about your environment:

  • Angular version: 2.0.0-rc.5
  • Browser: [all | Chrome XX | Firefox XX | IE XX | Safari XX | Mobile Chrome XX | Android X.X Web Browser | iOS XX Safari | iOS XX UIWebView | iOS XX WKWebView ]
  • Language: [all | TypeScript X.X | ES6/7 | ES5]

@MikeRyan52 @meenie @vsavkin

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 9
  • Comments: 15 (8 by maintainers)

Most upvoted comments

@ersandeepranjit @NathanWalker you probably need to upgrade to latest router beta also which is 3.1.0-beta.0. Its still versioned separate from the rest of the Angular packages

This issue should be fixed once https://github.com/angular/angular/pull/11656 lands

When will this be fixed as , AuthGuard Service could not be implemented without this ?

ngOnInit is the same effect