1

I have checkbox column in mat-table to select all or some items. I am getting the selected ids but struggling to put the selected userIDs in an array of object. How can I add the selected items in an array named userIDs?

The Ts file:

 userIDs: any[];
 sendRegretMail() {
  this.selection.selected.forEach(s => console.log(s.id));
  }

This is the body of my post request:enter image description here

2 Answers 2

2

For your current solution

userIDs: any[];
sendRegretMail() {
  this.selection.selected.forEach(s => {
    console.log(s.id);
    userIDs.push({"id": s.id}); // Just push object of id with define array
  });
}

Another Solution

this.userIDs = this.selection.selected.map(o => ({id: o.id}));
Sign up to request clarification or add additional context in comments.

1 Comment

2nd one is okay but for 1st solution, i need to initiate userIDs like userIDs = [ ]; otherwise push() shows undefined. Thnx for the solution.
1

What about

userIDs = this.selection.selected.map(s => ({id: s.id}));

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.