Angular routerLink scroll to top
Ngày đăng:
16/12/2021
Trả lời:
0
Lượt xem:
176
Show angular router scroll to top of page on routerLink click code exampleExample 1: scroll to top angular//inside the app.component.html add (activate): <router-outlet (activate)="onActivate($event)"></router-outlet> //inside app.component.ts, add inside the class of the component: export class AppComponent { onActivate(event) { window.scroll(0,0); //or document.body.scrollTop = 0; //or document.querySelector('body').scrollTo(0,0) } }Example 2: scroll to top when routing angularimport { Component, OnInit } from '@angular/core'; import { Router, NavigationEnd } from '@angular/router'; @Component({ selector: 'my-app', template: ' |