Using return of one AngularJS method in another controllerJS

1

I have this method in my controllerJS script and would need to use the response of this method on another controllerJs.

How do I do it?

app.controller("loginController", function($scope, $http, $location){

$scope.usuarios = {};

        $scope.autenticar = function() {    

                $http.post("/usuarioLogadoPermissoes", $scope.usuarios).then(
                        function(response) {
                            $scope.usuarios = response.data;
                            var jsonAux = JSON.stringify(response.data);
                            localStorage.setItem("usuarioLogado",jsonAux);                                  
                        },
                        function(response) {
                            console.log(response);
                        });

            };  
});
    
asked by anonymous 19.10.2017 / 15:12

1 answer

1

Create a service to help you with this task, so the code is still reusable.

Here's an example (it may contain errors, I've run it).

link

To help you improve the legibility of the pod, use John Papa's Style Guide:

link

    
19.10.2017 / 15:36