我想要做的是有一个与chrome中的刷新按钮完全相同的按钮。我试过了location.reload(),它似乎并没有真正做任何事情。有没有办法做到这一点?
exit() {
location.reload();
}
<button [routerLink]="['/dashboard']" (click)="exit()">Exit</button>
答案 0 :(得分:4)
试试这个:window.location.reload();
答案 1 :(得分:0)
这将重新加载到默认路由页面
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();
}
}
答案 2 :(得分:-1)
如何使用
HTML
<button (click)=‘reload()’>click me</button>
TS
reload(){
// any other execution
this.ngOnInit()
}