How to pass global variable value from one function to another function in angular?
I have 2 global variables as:
$scope.genewtId = null;
$scope.data1 = null;
I have 2 angular functions which look as below:
$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){
// here response is having an error
$scope.data1 = response.data;
console.log($scope.data1.toString());
}, function(error){
console.log(error.statusText);
});
};
When I pass value of $scope.genewtId
from one function to another function, I get an error
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, console.log($scope.genewtId);
is returning a value 787651
which means it is not null.
Please suggest if it can be implemented using $rootScope.$broadcast