0
I have an angular design, of which with the $routeProvider
define my views and call the appropriate controllers, and use the <ng-view></ng-view>
to present them on my website.
They are few pages, but they are pages with a scroll bar, and when clicking on a link I change from one view to another <a ng-href="/projeto/#/produto/{{produtoId}}>{{produtoNome}}</a>
.
However, when it goes to the next page, the scrolling is at the same height, it does not go back to the top, I know it is because it is a SPA, it is not literally changing pages. But there is some easy way of angular, of whenever change route, scrolling the page always return to the top?
Thank you.
I think this is what you’re looking for https://docs.angularjs.org/api/ng/service/$anchorScroll
– MarceloBoni
@Marcelobonifazio actually no, I will try to assemble an example of my case and already edit the question.
– Aldo Fernandes Junior
Take a look :) http://stackoverflow.com/a/27430246/3956218
– MarceloBoni
@Marcelobonifazio Caraca! is exactly what I wanted! hahaha, I looked at the q theory that should do what I need! however I’m not getting to do hahaha, I need some angular dependency for this $rootScope. $on? vi que o autor da pergunta usa o angular-ui-route, eu uso apenas o angular-route. isso implica no evento $stateChangeSuccess? Obrigado :D
– Aldo Fernandes Junior
I think to use Location.href='#height'; it would be simpler in your case, I will edit Thiago’s answer using, see if it works... it’s okay to use native javascript functions within an angular $Scope, it works the same way :)
– MarceloBoni
If you can create a minimal example with what you have, maybe to try to help you using the angular example, you can notice that it uses pure javascript to anchor the element
– MarceloBoni
Post only the code when you go to the next page Aldo
– MarceloBoni
@Marcelobonifazio I navigate between the views with the
<a ng-href="/#/...rota">
with even a normal link.– Aldo Fernandes Junior