I have a list of books and each book has id, name, and list of retailers. What I would like to do is to load up a page where I can use checkboxes to select/unselect retailers. When the book edit page is first loaded, the full list of retailers (each with a checkbox) are shown and then those that are the existing retailers for the book are checked.
app.js
allRetailers = $resource('/api/retailers');
currentRetailers = $resource('/api/books/:bookId/retailers')
partial.html
<span ng-repeat="retailer in allRetailers">
<input type='checkbox' value='{{retailer .id}}' ng-model="book.isExistingRetailer(retailer)" >{{retailer .name}}<br/>
</span>
Getting the full list of retailers and saving only the checked ones is not the problem. The problem I am having is pre-populate the checkboxes that are existing/current retailers.
I have looked at How do I bind to list of checkbox values with AngularJS? but it's not quite what I need. Thanks in advance to your replies.