Refresh table after inserting into the bank AngularJs

1

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>
    
asked by anonymous 22.09.2015 / 21:37

1 answer

1

In your code instead of:

  

$ scope.colaborators = contributors.data

change to:

  

$ scope.colaboradores.push (contributor)

Note that you are setting the initial value for $ scope.colors after saving a new employee. The correct would be to include the new employee in the existing list.

    
22.09.2015 / 22:06