angular2-course
angular2-course copied to clipboard
Why do I need to ROUTER_PROVIDERS to boot.ts?
If I need to add ROUTER_PROVIDERS to every component it's required, why I need to add it also too boot.ts?
I think you are confusing ROUTER_PROVIDERS
and ROUTER_DIRECTIVES
. If I understand it correctly, ROUTER_PROVIDERS
initializes navigation between pages (which is required once in boot.ts
), and ROUTER_DIRECTIVES
is used anytime you would use RouterLink
or RouterOutlet
.
Yeah, it's a pain. But there seem to be some work arounds:
http://stackoverflow.com/questions/35878966/router-directives-in-two-places-for-same-purpose
Obviously adding it everytime you're using either of one of them is annoying, so you can make it simpler by using PLATFORM_DIRECTIVES. This way you'll add it once in your application and it will be available across of it.
bootstrap(App, [
provide(PLATFORM_DIRECTIVES, {useValue: [ROUTER_DIRECTIVES], multi: true})
]);
Added: It appears that this may become a thing built right into Angular: https://github.com/angular/angular/issues/5938
Hi Patrick,
Thank you so much for your help !!!
Best regards, Ori
On Wed, Sep 28, 2016 at 6:15 AM, Patrick Kleckner [email protected] wrote:
I think you are confusing ROUTER_PROVIDERS and ROUTER_DIRECTIVES. If I understand it correctly, ROUTER_PROVIDERS initializes navigation between pages (which is required once in boot.ts), and ROUTER_DIRECTIVES is used anytime you would use RouterLink or RouterOutlet.
Yeah, it's a pain. But there seem to be some work arounds:
http://stackoverflow.com/questions/35878966/router- directives-in-two-places-for-same-purpose
Obviously adding it everytime you're using either of one of them is annoying, so you can make it simpler by using PLATFORM_DIRECTIVES. This way you'll add it once in your application and it will be available across of it.
bootstrap(App, [ provide(PLATFORM_DIRECTIVES, {useValue: [ROUTER_DIRECTIVES], multi: true}) ]);
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/mosh-hamedani/angular2-course/issues/3#issuecomment-250061214, or mute the thread https://github.com/notifications/unsubscribe-auth/AL6gXl6yClQaHvSjA-_qApHbiKtkc_vZks5qudu4gaJpZM4KHvN4 .