0

how am I able to do this? I am building a system which I can mark multiple checkbox then delete them simultaneously.

html

<input type="checkbox" (click)="selChk(member.id)">

component

 selChk(val) {
  let id = [];

  let ids = id.push(val);
  console.log(ids);
 }

I like to output like this:

["0","1","2","3","4","5"]

1 Answer 1

1

You are creating a new array whenever you click the button. Declare it in your class instead of inside the function.

ids= [];

selChk(val) {
  this.ids.push(val);
  console.log(this.ids);
 }
Sign up to request clarification or add additional context in comments.

3 Comments

hahahah I did this before but with a little difference, but thanks it works :)
Hi can I ask again, How can I remove the value from array when I uncheck the checkbox?
it is possible. you can use the .splice() function and use the index of the member to remove it from the list

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.