Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

ngInclude compilation ignores autoscroll attribute #8848

Closed
shaungrady opened this issue Aug 29, 2014 · 2 comments
Closed

ngInclude compilation ignores autoscroll attribute #8848

shaungrady opened this issue Aug 29, 2014 · 2 comments

Comments

@shaungrady
Copy link

$AnchorScroll is instantiated when ngInclude is compiled. Instantiation sets $AnchorScroll's watcher and calls the listener, scrolling the window to the top:
https://github.com/angular/angular.js/blob/master/src/ng/anchorScroll.js#L96

It seems that checking for $location.hash inequality in autoScrollWatchAction() before calling scroll() would fix this issue, though I'm not familiar enough with $AnchorScroll to know if that would have wider implications.

I understand that, technically, the instantiation of $AnchorScroll is unrelated to ngIncude's autoscroll attribute, but it certainly seems counterintuitive that this current behavior exists.

Example Plunkr:
http://plnkr.co/edit/XMuTqFmvKB7LzRyuzLSs?p=preview

@caitp caitp modified the milestones: 1.3.0-rc.2, 1.3.0 Sep 3, 2014
@caitp
Copy link
Contributor

caitp commented Sep 3, 2014

I can see why this is an issue, but I don't know how quickly this can be fixed.

@IgorMinar
Copy link
Contributor

@shaungrady as you described the problem is that $anchorScroll does scrolling when it initializes, which usually is not a problem unless you are initializing it while the application is already running and scroll position is different than 0,0.

workaround for now is to force early initialization of $anchorScroll by injecting it to a controller or a run block of a module: http://plnkr.co/edit/IQsdTD6t3O1h6UMPzozL?p=preview

I haven't thought through all the cornercases but I think your proposed solution is correct.

IgorMinar added a commit to IgorMinar/angular.js that referenced this issue Oct 2, 2014
IgorMinar added a commit to IgorMinar/angular.js that referenced this issue Oct 2, 2014
bullgare pushed a commit to bullgare/angular.js that referenced this issue Oct 9, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants