ngSmoothScroll
ngSmoothScroll copied to clipboard
not compatible with ui-sref
I've added a scroll-to attribute to an existing tag with a ui-sref attribute and the scrolling seems to negate the state change.
So the effect is that the scroll works ok, but the ui-router state doesn't change. For now, I'm using a callback to explicitly change the state, but I'd much rather have it work as expected:
Nav link
smoothly scrolls to the target point and changes state.
Any thoughts?
I'm facing the same issue.
So do I
+1 same here
+1
+1
+1 Same with my current project
This and #68 are related, it is the return false
in the click handler which stops the event from propagating to other handlers.
This is related to jQuery and jQuery's events and how angular uses jQuery (instead of jqLite) when it is present when angular loads. Essentially, return false
from within a jQuery event handler is effectively the same as calling both event.preventDefault
and event.stopPropagation
on the passed jQuery.Event object. This causes it to not trigger other handlers.
Workaround: Load angular before jQuery. Angular will use jqLite Note: If some of your angular logic (or other third-party angular logic) depend on angular using jQuery instead of the default jqLite, it will break.
Fix: Remove the return false
, it is not exactly needed since event.preventDefault
is called. I am not 100% sure if jqLite's event will always have preventDefault
, but it is currently assumed to always be there anyways (the current code does not check if it exists before it calls it), something like event.preventDefault ? event.preventDefault() : event.returnValue = false;
works well and will work in IE too.
More infotmation about angular and jqLite vs jQuery: https://docs.angularjs.org/api/ng/function/angular.element More information about jQuery events vs regular events: http://stackoverflow.com/a/1357151/1873485
I haven't included jQuery. Still facing this issue.