angular 路由切换->滚动条的位置如何回到顶部

问题:angular 路由切换浏览器记住滚动条的位置

解决:

import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';

declare var $: any;

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
})
export class AppComponent implements OnInit {
  title = 'app';
  constructor(public router: Router) {

  }

  ngOnInit() {

    this.router.events
      .subscribe((event) => {
        $(window).scrollTop(0);

      });


  }


}

 

你可能感兴趣的:(angular5/6)