I seem to be facing an issue with a seemingly straightforward function that creates an array - and I'm unable to pinpoint the root cause of the problem. It's probably something simple, but for some reason, it eludes me.
Here is the function in question:
private onSelection(selection)
{
if (selection)
{
const selectionsArray = [];
selectionsArray.push(selection);
console.log(selectionsArray);
console.log(selectionsArray.length);
return selectionsArray;
}
}
The "selection" is passed through a checkbox, like this:
<md-checkbox (click)="onSelection('A')">A</md-checkbox>
<md-checkbox (click)="onSelection('B')">B</md-checkbox>
<md-checkbox (click)="onSelection('C')">C</md-checkbox>
Currently, irrespective of which checkboxes are clicked, my array only contains one item at all times, as evident from the length being constantly 1 when logged to the console. What could I possibly be overlooking here? Why isn't the array expanding to accommodate multiple selections being added?