CopyPastor

Detecting plagiarism made easy.

Score: -1; Reported for: Open both answers

Possible Plagiarism

Reposted on 2018-01-29

Original Post

Original - Posted on 2016-09-20



            
Present in both answers; Present only in the new answer; Present only in the old answer;

This is normal in angular 5. However if you want to change this behaviour, you can listen to route changes and scroll to top.
Below code is working for scroll to top
import { Component, OnInit } from '@angular/core'; import { Router, NavigationEnd } from '@angular/router'; @Component({ selector: 'my-app', template: '<ng-content></ng-content>', }) export class MyAppComponent implements OnInit { constructor(private router: Router) { } ngOnInit() { this.router.events.subscribe((e) => { if (!(e instanceof NavigationEnd)) { return; } window.scrollTo(0, 0) }); } }
You can register a route change listener on your main component and scroll to top on route changes.
import { Component, OnInit } from '@angular/core'; import { Router, NavigationEnd } from '@angular/router'; @Component({ selector: 'my-app', template: '<ng-content></ng-content>', }) export class MyAppComponent implements OnInit { constructor(private router: Router) { } ngOnInit() { this.router.events.subscribe((evt) => { if (!(evt instanceof NavigationEnd)) { return; } window.scrollTo(0, 0) }); } }


        
Present in both answers; Present only in the new answer; Present only in the old answer;