1
I have a modal with a form
, fill that form
and I click the save button and the data is saved in the database, but I have to give a F5
to update the table. How can I update the table after entering this data?
That’s actually how I upload the data from the API:
$scope.colaboradores = colaboradores.data;
Full controller:
angular.module("oraculo").controller("colaboradorController", function($scope, $routeParams, $location, colaboradores, colaboradorAPI){
$scope.colaboradores = colaboradores.data;
$scope.adicionarColaborador = function(colaborador){
colaboradorAPI.saveColaborador(colaborador).success(function(data){
console.log("Salvar!");
$scope.colaboradores = colaboradores.data;
delete $scope.colaborador;
$scope.colaboradorForm.$setPristine();
})
.error(function(response, status){
console.log("erro "+status);
});
}
});
Route Configuration:
angular.module("oraculo").config(function($routeProvider){
$routeProvider.when("/home", {
templateUrl: "public/views/colaborador.html",
controller: "colaboradorController",
resolve: {
colaboradores: function(colaboradorAPI){
return colaboradorAPI.getColaboradores();
}
}
});
$routeProvider.otherwise({redirectTo: "/home"});
});
I’ve tried putting a $scope.colaboradores = colaboradores.data;
in the method adicionarColaborador
but it didn’t work.
Save button inside the modal:
<button class="btn btn-success btn-block" ng-click="adicionarColaborador(colaborador)" ng-disabled="colaboradorForm.$invalid" data-dismiss="modal">
<span class="glyphicon glyphicon-floppy-disk" aria-hidden="true"></span>
Salvar
</button>
Try giving a $Scope. $apply() after $Scope.contributors = contributors.data;
– Emir Marques
When I try to give a
$scope.$apply();
of that mistake:Error: [$rootScope:inprog] $digest already in progress
– DiegoAugusto
Remove delete $Scope.contributor;
– Emir Marques
Still the same mistake.
– DiegoAugusto