0
Good morning, everyone,
I would like to know how to leave this code below more performatic.
I have two functions that the only difference between them is $Location.path
How can I turn this into a function with just these two conditions?
Follow the example.
$scope.initLogin = function() {
        if ($localStorage.hasOwnProperty("accessToken") === true) {
            $http.get("https://graph.facebook.com/v2.6/me", {
                params: {
                    access_token: $localStorage.accessToken,
                    fields: "name, email",
                    format: "json"
                }
            }).then(function(result) {
                $scope.loginData = result.data;
            }, function(error) {
                console.log(error);
            });
        } else {
            alert("Houve um erro na solicitação, tente novamente.");
            $location.path("/login");
        }
    };
    $scope.initRegister = function() {
        if ($localStorage.hasOwnProperty("accessToken") === true) {
            $http.get("https://graph.facebook.com/v2.6/me", {
                params: {
                    access_token: $localStorage.accessToken,
                    fields: "name, email",
                    format: "json"
                }
            }).then(function(result) {
                $scope.registerData = result.data;
            }, function(error) {
                console.log(error);
            });
        } else {
            alert("Houve um erro na solicitação, tente novamente.");
            $location.path("/pre-register");
        }
    };
Do not simply pass the path by parameter?
– tpsilva
Speaks tpsilva, I left returning to a route only even, after logged in the user will update when it deems necessary the other information I need. Vlw
– estevammr