Open In App

How to refresh entire application when date is changed in angular 9 ?

In this example, we will see how to refresh the application when the date is changed in angularJS.

Approach:



Code Implementation:

app.component.ts:






import { Component } from '@angular/core';
  
@Component({
    selector: 'my-app',
    templateUrl: './app.component.html',
    styleUrls: ['./app.component.css']
})
export class AppComponent {
    constructor() { }
  
    // Function to reload the application
    refreshPage() {
        window.location.reload();
    }
}

app.component.html:




<h1>Hello User !</h1>
  
<p>Change the date to refresh the application.</p>
  
<input type="date" (change)="refreshPage()">

app.module.ts:




import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { AppComponent } from './app.component';
  
@NgModule({
    imports:
        [
            BrowserModule,
            FormsModule
        ],
    declarations:
        [
            AppComponent
        ],
    bootstrap:
        [
            AppComponent
        ]
})
  
export class AppModule { }

Output:


Article Tags :