TL;DR: With Angular UI Router, is it possible to autoscroll to a view of the same state that the template displaying it belongs to?
The Setup
I have an Angular 1.4.1
app, using UI Router 0.2.15
and Angular Material 0.10.0
.
There is a parent state called website
and three child states: home
, foo
and bar
.
The parent state has a wrapper
view, which is displayed via the <ui-view>
tag in index.html
. It also has two other views, header@website
and footer@website
, which it displays via the wrapper
view template.
Each of the three child states has a main
view, which is displayed via the parent state's wrapper
view template.
What I Expect
In the parent state's wrapper
view template, when I set autoscroll="true"
on the ui-view
tag for the header@website
view, I expect that the page will scroll to the top whenever the state changes. See the accepted answer of this SO question.
What Is Happening
When any of the ui-sref
links in the footer is clicked, the page does not scroll to the top.
What I've Tried
If I put autoscroll="true"
on the ui-view
tag for the main view, it works as expected. This is not what I want, however, because the header is hidden from view even when you navigate to a state from the address bar.
What I Suspect
I think the problem has to do with the fact that header@website
is a view that belongs to the website
state, and that autoscroll
only works for views that normally are displayed on the current template. In other words, normally the header
view would be displayed via index.html
, not wrapper.html
.
The Question
Is my suspicion above correct? Do I need to refactor, or is there a way to make this work as is?
Thanks in advance!