Getting Angular2 error 'No provider for Router! (RouterOutlet -> Router)'

后端 未结 6 811
你的背包
你的背包 2020-12-09 08:07

I use Angular2 alpha39 and Babel to transpile the ES6 JS file. I\'m not using typescript.

I created a component which displays correctly. I added a

6条回答
  •  难免孤独
    2020-12-09 09:03

    This can save someone an hour:

    You get this error if you don't even use routing (for example temporary, maybe you don't import routing config and router-outlet is commented out) BUT you are using Router or ActivatedRoute in some component constructor via dependency injection, like this:

    @Component({...}})
    export class SomeComponent {
    constructor(private _router: Router, private _route: ActivatedRoute) {
    //may be you are not using _route/_route at the moment at all!
    }
    ...
    }
    

提交回复
热议问题