I am seeking guidance on how to implement ng-repeat
in order to transfer data from one table to another. Essentially, I have a "master" table that displays data fetched from an API request. Each row in this table has a button labeled "favorite-this-row". When a user clicks this button, I want the respective row to be moved to a table named "favorite-table" where the data will be displayed.
Here is a snippet of my "Master" table:
<md-card flex="45" flex-sm="100" flex-md="100" flex-xs="100"
ng-show="(account|filter:searchName).length > 0"
ng-repeat="account in containers | groupBy: 'accountId' | toArray | filter:searchName track by $index ">
... HTML code omitted for brevity...
**//Favorite button**
<md-button ng-init="item.isfavorite = false;"
ng-class="{yellow : item.isfavorite}"
ng-click="item.isfavorite =!item.isfavorite; AddFavorite(item.isfavorite,container.containerId)"
class="md-icon-button md-accent md-warn" aria-label="Favorite">
<ng-md-icon icon="favorite" ng-init="item.isfavorite = false;"></ng-md-icon>
</md-button>
<p ng-if="item.isfavorite">Remove from favorites - {{item.isfavorite}} </p>
<p ng-if="!item.isfavorite">Add to favorite</p>
And this is my "Favorite" table:
<table>
<tr ng-repeat="x in containers" ng-show="item.isfavorite">
<td>s{{ x.containerId }}</td>
<td>s{{ x.accountId }}</td>
</tr>
</table>
Upon clicking the
<md-button ng-init="item.isfavorite = false;" ....>
, I aim to move the row to the "Favorite" table displaying containerId
and accountId
. Although I have used ng-show="item.isfavorite"
, the functionality does not seem to work as expected.
The function
AddFavorite(item.isfavorite,container.containerId)"
is temporarily a placeholder console.log
in the controller.
I would appreciate any assistance or insights on this matter. Thank you!