I have a modal with a form
, I fill in this form
and click the save button and the data is saved in the database, however I have to give F5
to update the table. How can I update the table after inserting this data?
This is how I load the data coming 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 Setup:
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 have tried to put a $scope.colaboradores = colaboradores.data;
in method adicionarColaborador
but it did not work.
Save button that stays within 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>