I how to arrays, one(array1) has some objects while the other(array2) has a list of objects that I want to choose from and push to array1.
.html
<div class="forArray1">
<table >
<tr *ngFor="list1 of array1">
<td>{{list1.name}}</td>
<td><button (click)=removeFunction()>Remove</button><td>
</tr>
<table>
</div>
<div class="forArray2">
<table >
<tr *ngFor="list2 of array2">
<td>{{list2.name}}</td>
<td><button (click)=addFunction()>Add</button><td>
</tr>
<table>
</div>
How to push the row object from arry2 list to arry1 list after clicking on the "Add" button on a specific object? Something like get by ID and push.
json
array1 = [
{
"type": "toyota",
"year": "2013"
}]
***************************************
array2 = [
{
"type": "toyota",
"year": "2013"
},
{
"type": "audi",
"year": "2010"
},
{
"type": "honda",
"year": "2014"
},
{
"type": "ford",
"year": "2018"
}]
.ts
array1 = [];
array2 = [];
//add an obj to array1 and delete it from array2
addFunction() {
//TODO
}
//it will remove the an obj from array1
removeFunction(){
//TODO
}
How to complete the functions? Suggestion on better approach is also fine.