I am facing an issue where I need to update a specific array within my HTML template from a callback function triggered by an event. However, when trying to access the array inside the callback, it shows undefined
.
export class HomePage {
constructor(public navCtrl: NavController) {
let consumer: string[]; // <=== The array that needs updating
const realtime = new Ably.Realtime('API-KEY');
const channel = realtime.channels.get("test");
channel.subscribe((msg) => {
console.log("Received: " + msg.data);
consumer.push(msg.data); // <=== Unfortunately, "consumer" is undefined at this point
});
}
}
HTML TEMPLATE
<div>
<ul *ngFor="let item of consumer">
<li>{{item}}</li>
</ul>
</div>