Good morning,
I would like to know how to make this code more performance-oriented.
I have two functions that the only difference between them is $ location.path
How can I make this a function with only 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");
}
};