I've been scratching my head for days over this, and excuse my lack of JavaScript expertise as that may be the problem.
I have an Angular application that, among other things, has a Queue of items a user will work. I have a Service that manages this queue (current item, move, complete, etc.). The controller I created fetches the current queue item's details from the server, then displays them.
The issue I'm having is the Service is correctly moving through the Queue of objects, setting the current item to the array item at the current index. However, the Controller never sees the current item change.
Here is a basic example for explanation. A working example is at http://jsfiddle.net/Surefire_gf/pjMrh/2/, you'll need to view console to see output.
// ... service code...
var items = [];
var currentItem;
var currentIndex;
...
var moveNext = function() {
currentIndex = currentIndex + 1;
currentItem = items[currentIndex];
};
// ... controller code ...
var skip = function() {
service.moveNext();
fetchData(service.currentItem); //THIS NEVER CHANGES, ALWAYS UNDEFINED
};
Setting the current item variable to a position in the array is seen within the service, but never the controller. However, if I do an angular.extend instead of directly referencing the array, it works. Does anyone know what might be going on?