I have the following setup in my controller which I would expect to update my view appropriately, but it does not until I refresh the page:
var vm = this;
var loadingGames = $q.defer();
var getGames = function() {
playersService.getGames({
playerId: playerId
}).$promise.then(function(data) {
vm.games = data;
loadingGames.resolve();
});
};
var init = function() {
getGames();
}
init();
var updateSchedule = function() {
getGames();
loadingGames.promise.then(function() {
populateOptions(vm.games);
vm.tableParams.reload();
});
};
vm.performAction = function(action, gameId, gameType) {
utilitiesService.performOperation(action, gameId, gameType).then(
function() {
updateSchedule();
},
function(httpError) {
alert('Couldn\'t '+ action +' game: ' + httpError);
});
};
var populateOptions = function(games) {
angular.forEach(games, function(game) {
game.options = getOptions(game);
});
};
When I click the performAction button in my UI I expect to see updated vm.games in my view. However, I always need to refresh the page to see the changes. I know this is most likely related to $scope.$apply but I'm not grasping it at the moment.
populateOptionsandvm.tableParams.reload()are synchronous?thisrefers to the controller. I usecontrollerAssyntax.getOptionsreturn a promise? Is it an angular promise?