In my controller I have an array of objects (I'm just getting started, so forgive me if this is terribly naive or something):
$scope.links = [
{
'votes': 6,
'voted_on': false
},
{
'votes': 7,
'voted_on': false
}
];
I want to list these out in the view and modify some of the properties on click, maintaining some complex state reflecting the change in the DOM:
<ul>
<li ng-repeat="link for links">
<a ng-click="updateProperties()">Vote</a>
{{link.votes}}
</li>
</ul>
You know, I would like updateProperties()
to manage a lot of stateful logic (change the color of the {{link.votes}}
, increment link.votes
, disallow incrementing if they have already voted, etc. ). I get that I need to define the function on $scope
but I'm just not sure what that would look like, so help would be much appreciated. Thanks.