I have a question about ng-repeat and to move data from one table to another. Basically i have one table that is "master" and shows all the data from API request, after i populate it in a table i have a button on each row that works like "favorite-this-row". After a user click on "favorite-this-row" i want it to move the row to another table called "favorite-table" and show the data here.
This is my "Master"-table: (i wont paste whole table just the needy parts)
<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 ">
... Bunch of HTML code down......
**//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>
Now 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>
When i click on the button <md-button ng-init="item.isfavorite = false;" ....> i want it to slice and move to my favorite table that just repeats containerId and accountId. as you can see ive added ng-show="item.isfavorite" but it does not work/show.
AddFavorite(item.isfavorite,container.containerId)" is just a console.log in controller.
Hope someone could help me, thanks!
ng-init="item.isfavorite = false;"as it should be by default or if it's not I would suggest you to initialize it in controller rather than DOM. Also seems like you are looping throughaccount in containersso you would haveaccountinstead ofitem.item.isfavoritetoaccount.isfavoriteshould be enough to fix your issue. It does show in favorite because you are repeatingxthroughcontainersand using samexto show child properties while in masters table you are repeatingaccountthroughcontainersbut you are usingitemwhich by your provided code does not exist.