I am just trying to reload the component without refreshing the page.
Here is the code for that:
import { Component, VERSION, OnInit } from '@angular/core';
import { Router, ActivatedRoute } from '@angular/router'
@Component({
selector: 'my-home',
templateUrl: './home.component.html'
})
export class HomeComponent implements OnInit {
name = 'Angular ' + VERSION.major;
time = new Date().getSeconds();
constructor(private route: ActivatedRoute, private router: Router){
this.router.routeReuseStrategy.shouldReuseRoute = () => false;
this.time = new Date().getSeconds(); //updating the time on load.
}
ngOnInit(){
console.log('iniit');
}
}
In my html I have a button to reload the component by navigating to the url again. Please advice if I am wrong
<hello name="{{ name }}" time="{{time}}"></hello>
<p>
Start editing to see some magic happen :) {{time}}
</p>
<a [routerLink]="['/home']">Go to Home </a>
When I click on the button, it is supposed to update the time because of the component reload. But whenever I click on the link, no update happens on the time.
Can anyone advice me how to reload the component when we need without reloading my window (window reload kills my auth info).