Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No provider for Router! #40

Closed
dolanmiu opened this issue Oct 9, 2016 · 4 comments
Closed

No provider for Router! #40

dolanmiu opened this issue Oct 9, 2016 · 4 comments
Milestone

Comments

@dolanmiu
Copy link

dolanmiu commented Oct 9, 2016

I'm using version 3.1.2 of ng2-page-scroll

I am doing the absolute bare minimum to get it to work, and I can't get it to work, I get the following error:

error_handler.js:45EXCEPTION: Error in ./NavComponent class NavComponent - inline template:5:16 
    caused by: No provider for Router!
    ErrorHandler.handleError @ error_handler.js:45
    (anonymous function) @ application_ref.js:209
    ZoneDelegate.invoke @ zone.js:192
    onInvoke @ ng_zone_impl.js:43
    ZoneDelegate.invoke @ zone.js:191
    Zone.run @ zone.js:85
    (anonymous function) @ zone.js:451
    ZoneDelegate.invokeTask @ zone.js:225
    onInvokeTask @ ng_zone_impl.js:34
    ZoneDelegate.invokeTask @ zone.js:224
    Zone.runTask @ zone.js:125
    drainMicroTaskQueue @ zone.js:357

error_handler.js:47ORIGINAL EXCEPTION: No provider for Router!

Screenshot here:
screen shot 2016-10-09 at 03 39 51

@Nolanus
Copy link
Owner

Nolanus commented Oct 10, 2016

Hello @dolanmiu,

according to your screenshot you're trying to run your own application and not the demo application from this repo. The error No provider for Router! notifies you that you're injecting the router somewhere without having specified where the router comes from (missing a definition how the router is provided).
Please check out the official angular2 guide for the router or this frequently updated stackoverflow question on how to properly setup the angular2 router.

@Nolanus
Copy link
Owner

Nolanus commented Oct 13, 2016

As the pageScroll directive has the capability of listening to route changes before starting the scroll animation, it has a dependency on @angular/router. If the router is not present you will see this error.

As immediate workaround adding either adding the angular router to your project or using the PageScrollService instead of the directive should fix the problem. I'll have to investigate whether there is a way to make the dependency "weaker", but I fear this is not possible.

@ValentinFunk
Copy link

@Nolanus i think you can use the @optional() Decorator to mark the Dependency optional to the Injector - you should simply get null as router then

@Nolanus Nolanus mentioned this issue Feb 25, 2017
@Nolanus
Copy link
Owner

Nolanus commented Oct 30, 2017

It is now possible to create an angular app (using latest angular-cli) without @angular/router dependency and use the directive and service to trigger scrolls. Anyhow, this package will remain a peerDependency to inform the package users that not all functionality of ng2PageScroll will be available without the angular router.

@Nolanus Nolanus closed this as completed Oct 30, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants