Implemented a code in an Angular component to retrieve data from a service every 10 seconds on initialization. Now, I need to find a way to stop the interval after a certain period of time such as 5 minutes or when all the necessary data has been collected.
Below is the code snippet for the component:
GetRecords() {
Interval(10000).pipe(
startWith(0),
switchMap(() => this.getService.getData())
).subscribe(data => {
this.code = data;
});
}