I am new to AngularJS and I am trying to learn a bit more about the possibilities with ng-repeat. I have put together some code to try and learn a bit more but I have hit some issues that I don't understand.
Here is the code:
The HTML:
<ul class="list-unstyled">
<li ng-repeat="worker in workers">
<section class="well col-md-6 col-md-offset-3">
<h1 class="h3 col-md-6 text-right" style="margin-top: 0"><a>{{worker.worker_name}} {{ getTipCount(worker.id) }}</a></h1>
</section>
</li>
</ul>
And in my Controller:
$scope.getTipCount = (workerId) ->
WorkerTips = $resource("/workers/#{workerId}", { workerId: "@id", format: 'json' })
json = WorkerTips .get ((res) ->
$scope.workertipscount = res.worker.tips.lengh
)
In the JSON each worker object has an array of tips and what I am trying to do is to get the count of how many tips each worker has. To do this I need to get the id from the worker through ng-repeat and then pass that to a function that then gets me the count of tips from the JSON and displays it on the page.
However when I try to do this it looks like the page goes into an infinite loop and I get the following error:
Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting!
So I'm guessing my approach to pulling information out of a element in an ng-repeat and then sending it to a function that also gets sent to the ng-repeats view is incorrect? If so what is the correct approach to this for AngularJS?