I'm trying to use the setInterval() function in order to change text to the user every 3 seconds.
I tried looping with for loop but that doesn't work - I see the 'test 03' and that's it.
I can't 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 }}
Appreciate any help!