Reputation: 73
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:
Upvotes: 1
Views: 1012
Reputation: 779
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}));
Upvotes: 2
Reputation: 726
What about
userIDs = this.selection.selected.map(s => ({id: s.id}));
Upvotes: 1