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
@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;});
}
}
I don't prefer to do that through the client-side, it's okay to add a button to that run it, just imagine these cases:
I prefer to do that from the server-side, and you can update the time through an API to get the latest time or you can add a WebSocket to make it always updated.