Skip to content

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

@tramel-woodard

Description

@tramel-woodard

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions