I've got an object in my $scope
that contains a bunch of details about, say, an election. This object includes a voters
array of objects, each with an _id
:
$scope.election = {
voters: [
{ _id: '123' },
{ _id: '456' },
{ _id: '789' }
]
}
Also in my scope I have details about the currently logged in user:
$scope.user = { _id: '456' }
How can I bind ng-disabled to the presence of $scope.user._id
in the array of objects $scope.voters
?
What I've Tried
I have success simply displaying the presence of $scope.user._id
in $scope.election.voters
like this (Jade syntax):
pre(ng-bind="election.voters | filter:{user._id} | json")
When the current user is among the voters
, they get displayed. When they're not among the voters, I get an empty array. That seems quite close to what I want.
But using the same filter (sans | json
) with ng-disabled, I get the Angular Infinite $digest loop error.
Is this situation too complicated? Should I move it to a $filter
? If so, how would I go about making it generic enough to be useful in a number of situations (if that's even feasible)?