As I work with TypeScript and Angular, my goal is to establish an empty array in the testConnection function that can accommodate the addition of objects each time the function is triggered, without wiping out the existing contents of the array.
This is the testConnection function:
testConnection(system) {
var systemList = [];
this.service.testConnection(system)
.subscribe(conn => {
if (conn == 'Success') {
this.snackBarHandler.open('Connection Found', 'success');
system.isClicked = false;
system.connection = true;
systemList.push(system);
}
else {
this.snackBarHandler.open('Connection Failed', 'failure');
system.isClicked = false;
system.connection = false;
systemList.push(system);
}
}, err => console.log(err));
}
At present, the system object gets added to the array due to the current logic. However, since the empty array declaration exists within the function itself, it undergoes a reset upon every function call. Despite attempts to declare systemList at the top of the class as (systemList = any[]), referencing it within the function results in undefined output.
Is there a way for me to append system objects to the array whenever the function is executed, while retaining the existing objects in the array?