this is my component code. and i am using socket.on to get data from node server and then want to push that into a Typescript array. its showing error on push function. actually list array is undefined at this point.
import { Component } from '@angular/core';
import * as io from 'socket.io-client';
@Component({
selector: 'app-admin',
templateUrl: './admin.component.html',
styleUrls: ['./admin.component.css']
})
export class AdminComponent{
private socket: io.Socket;
private list: any[];
constructor() {
this.socket = io('wss://ngrk-buzzer-app.herokuapp.com');
this.socket.on('message', function (data) {
console.log(data);
this.list.push(data.from + " pressed Buzzer."); //this is where the error is
});
}
clearList(){
this.socket.emit("clear", "yes");
}
addItemInList(data){
}
}
what should i do to make this.list make defined?