Reputation: 307
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?
exit() {
location.reload();
}
<button [routerLink]="['/dashboard']" (click)="exit()">Exit</button>
Upvotes: 7
Views: 53003
Reputation: 1005
You can remove the [routerLink]="['/dashboard']"
from the button.
exit() {
window.location.reload();
}
<button (click)="exit()">Exit</button>
Upvotes: 0
Reputation: 124
What about using
HTML:
<button (click)="reload()">click me</button>
TS:
reload(){
// any other execution
this.ngOnInit()
}
Upvotes: -1
Reputation: 1505
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();
}
}
Upvotes: 2