Angular 2, links

0

I have a web in angular 2, with the routes set so that I can go browsing the web loading my different modules, when I click on a link the module I want is loaded, but the position of the scroll is maintained.

And I need that every time someone clicks on a link, the loaded module is shown from above as when you give a normal link in html that the page is loaded from above and the scroll position is up.

    
asked by Teodar 05.05.2017 в 11:40
source

1 answer

1

In the component that you define your router you should be listening to the activate event to do the scrollTop.

@Component({
  template: '<router-outlet
               (activate)="onActivate($event, outlet)" #outlet>
            </router-outlet>',
})
export class TuComponente {
  onActivate(e, outlet){
    outlet.scrollTop = 0;
  }
}
    
answered by 02.11.2017 в 02:28