I am having trouble trying to capture the product name of a checked checkbox's row and add it to an array. Additionally, I want to remove the product name from the array if the checkbox is unchecked. I attempted a solution but it is not functioning as expected. Any help would be greatly appreciated.
For a live demonstration, you can visit: https://stackblitz.com/edit/angular-b6urvc?file=src/app/app.component.ts
The code in app.component.ts is provided below:
getProduct(event){
if(event.target.checked)
{
const target = e.originalEvent.toElement.closest('tr');
let tdProduct = target.querySelector('td:nth-child(3)').innerText;
productArr.push(tdProduct);
} else {
const target = e.originalEvent.toElement.closest('tr');
let tdProductRemove = target.querySelector('td:nth-child(3)').innerText;
productArr.pop(tdProductRemove);
}
console.log(productArr);
}