How to transfer a global variable value between two Angular functions?
Here are the two global variables:
$scope.genewtId = null;
$scope.data1 = null;
The two Angular functions in question are:
$scope.getID = function() {
Service1.getId("abc").then(function(response){
$scope.genewtId = response.data[0].Id;
console.log($scope.genewtId);
}, function(error){
console.log(error.statusText);
});
};
$scope.getDetails = function() {
Service2.getDetails($scope.genewtId).then(function(response){
// encountering an error with the response
$scope.data1 = response.data;
console.log($scope.data1.toString());
}, function(error){
console.log(error.statusText);
});
};
When attempting to pass the value of $scope.genewtId
from one function to another, an error is being received:
message: "Failed to convert value of type 'java.lang.String' to required type 'java.lang.Integer'; nested exception is java.lang.NumberFormatException: For input string: "null"
However, the output of console.log($scope.genewtId);
shows a value of 787651
, indicating that it is not null.
If there's a way to implement this using $rootScope.$broadcast
, please advise.