When working with my application, I use Constants.getContants as a promise to retrieve all the necessary constants. I want to store this information in a $scope variable so that it can be easily accessed throughout the controller or application. However, I find that I have to repeat the call and perform operations on it whenever I need to access it. Even when I try to save it in the $scope, it remains unavailable outside of the corresponding handler. How can I address this issue?
Below is the code snippet I am currently using:
Constants.getConstants().then(function (AppContants) {
$scope.responseCount = AppContants.data.serverUrl+AppContants.data.appId
console.log($scope.responseCount);
//$scope.$apply();
});
console.log($scope.responseCount);
In addition to this, I am experiencing issues with the AJAX call going out of sync. I understand that actions should be taken inside the handler function to ensure they are executed only after a successful AJAX call. However, I also need to use these variables outside of the function. I have attempted to use $scope.$apply() but it hasn't resolved the problem. Is there a solution to this dilemma? Thank you in advance.