Within my $scope.users
, I have a list of items that are displayed.
Upon clicking on one of these items, a modal window pops up to confirm deletion. The deletion query functions correctly, but the changes are not reflected in the view for $scope.users
. This could be due to the fact that $scope.users
is not in the same controller.
Is there a solution to update the scope without resorting to using $rootscope?
app.controller('backController', ['$scope', '$http', '$rootScope','MyFunctions', '$location', '$modal',
function ($scope, $http, $rootScope, MyFunctions, $location, $modal) {
MyFunctions.getUsers().then(function (data) {
$scope.users = data;
});
$scope.openModalDeleteUser = function (user) {
$scope.user = user;
var modalInstance = $modal.open({
templateUrl: 'template/app/modalDeleteUser.html',
controller: 'modalDeleteUserController',
scope: $scope,
});
};
}]);
app.controller('modalDeleteUserController', ['$scope', '$modalInstance', 'MyFunctions',
function ($scope, $modalInstance, MyFunctions) {
$scope.delete = function(){
var data = {};
data['action'] = 'delete_user';
MyFunctions.updateData(data).then(function (response){
MyFunctions.getUsers().then(function (data) {
$scope.users = data;
console.log($scope.users); // Data retrieval is successful, but not updated in the view
});
});
$modalInstance.dismiss('cancel');
}
$scope.cancel = function () {
$modalInstance.dismiss('cancel');
};
}]);