vitalets / checklist-model

AngularJS directive for list of checkboxes
http://vitalets.github.io/checklist-model
MIT License
1.05k stars 206 forks source link

checkAll Not Working when Array is 'ID' Only ($scope.roles.map Functionality) #162

Open tramel-woodard opened 7 years ago

tramel-woodard commented 7 years ago

Actually, the poster of #49 had the same question, but the issue was closed without solving the original poster's issue of using the $scope.object.map functionality.

This is for the example where each object in the array has both an "id" and "text" field:

$scope.roles = [ { id: 1, text: 'guest' }, { id: 2, text: 'user', }, { id: 3, text: 'customer' }, { id: 4, text: 'admin' } ];

The original poster must use the $scope.object.map function in order to just return the id only (or whichever array you're using for your data source:

$scope.checkAll = function() { $scope.user.roles = $scope.roles.map(function(item) { return item.id; }); };

The error I'm receiving when clicking my "Check All" button for "id only" check all is the following:

TypeError: Cannot read property 'map' of undefined' at Scope.$scope.checkAll (file.js xx:xx)

I'm especially facing this issue when the "id" primary key of my object isn't simply id, but instead something like bookId.

Haven't been able to find the underlying issue for the last few days, wondering if someone is using the $scope.object.map function and facing a similar issue.