“gulir sudut ke atas” Kode Jawaban

gulir sudut ke atas

scrollToTop(){
	window.scroll(0,0);
}
ChernobylBob

gulir perubahan rute sudut ke atas

RouterModule.forRoot(appRoutes, { scrollPositionRestoration: 'enabled' })
TheGuyOnTheCorner

Gulir ke atas sudut atas

//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)
    
}
}
Grieving Gharial

Gulir ke atas saat merutekan sudut

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)
        });
    }
}
sachin_duhan

Jawaban yang mirip dengan “gulir sudut ke atas”

Pertanyaan yang mirip dengan “gulir sudut ke atas”

Lebih banyak jawaban terkait untuk “gulir sudut ke atas” di TypeScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya