I have a variable in my $scope
that contains information about an election, including a list of voters with unique IDs:
$scope.election = {
voters: [
{ _id: '123' },
{ _id: '456' },
{ _id: '789' }
]
}
Additionally, I also have details of the currently logged-in user stored in my scope:
$scope.user = { _id: '456' }
How can I use ng-disabled based on whether $scope.user._id
is present in the voters
array?
Methods Attempted
I managed to display if $scope.user._id
is among the voters
using this Jade syntax:
pre(ng-bind="election.voters | filter:{user._id} | json")
This code successfully displays the current user when they are a voter and shows an empty array when they are not. It's almost what I need.
However, when applying the same filter (without | json
) with ng-disabled, it results in an Angular Infinite $digest loop error.
Is this scenario too complex? Should I consider moving it into a $filter
? If so, how can I make it generic enough for broader usability (if possible)?