I'm facing an issue while attempting to use the setInterval()
function to update text for the user every 3 seconds.
My attempt at looping with a for loop has not been successful - I only see 'test 03' and nothing else.
I'm struggling to find a solution.
export class MessagesComponent implements OnInit {
items = ['test 01', 'test 02', 'test 03'];
currentItem: any;
private interval;
constructor() {}
ngOnInit() {
for (let i = 0; i < this.items.length; i++) {
this.interval = setInterval(() => {
this.currentItem = this.items[i];
}, 3000);
}
}
}
{{ currentItem }}
Any assistance would be greatly appreciated!