I have to create a component in angular that clean the data in the database (via a service call) every hour and displays the last clean time in HTML. Couple of question
- When we route from one component to another, does the component get auto destroyed and lose all its data?
- Is it possible to persist data and use it in the future?
@Component({
selector: 'demo-app',
template:`
<button (click)="clearData()"></button>
<h2>Last synced time: {{ time }}</h2>
`
})
export class AppComponent {
public time;
constructor(private demoService: DemoService) { }
// ----> this should be triggered every hour <----
clearData() {
this.demoService.deleteData()
.subscribe((lastCleanTime) => {this.time = lastCleanTime;});
}
}