typescript 带按钮的角度刷新页面

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/44442567/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 04:37:00  来源:igfitidea点击:

Angular refreshing page with a button

angulartypescript

提问by John

What I want to do is have a button that does the same thing as the refresh button in chrome does. I have tried location.reload(), and it doesn't seem to really do anything. Is there any way to do this?

我想要做的是有一个按钮,它的作用与 chrome 中的刷新按钮相同。我已经尝试了 location.reload(),但它似乎并没有真正做任何事情。有没有办法做到这一点?

exit() {
    location.reload();
  }

 <button [routerLink]="['/dashboard']" (click)="exit()">Exit</button>

回答by CodeWarrior

Try this: window.location.reload();

试试这个: window.location.reload();

回答by Crystal

This will reload to default route page

这将重新加载到默认路由页面

import { DOCUMENT } from '@angular/common';
import { Component, Inject } from '@angular/core';

@Component({
  selector: 'app-refresh-banner-notification',
  templateUrl: './refresh-banner-notification.component.html',
  styleUrls: ['./refresh-banner-notification.component.scss']
})
export class RefreshBannerNotificationComponent {

  constructor(
    @Inject(DOCUMENT) private _document: Document
  ) {}

  refreshPage() {
    this._document.defaultView.location.reload();
  }
}