When first starting out with angular I found myself having logic in my controllers which is not really what a controller id for. Loops, and app login in general, is best placed inside services made with module.factory, or one of the other options for doing so.
In this post I will be covering how I go about making a loop in a service, and using a controller to update the view with the latest data from that service.
For my example I will be making a service with module.factory called loop and use that in a controller.
The grab method returns a reference to the internal state object. Because it’s a reference I do not have to do anything weird in my controller. All I have to do is just simply set it to a property in $scope, and use it in my view.