【发布时间】:2019-09-26 19:46:05
【问题描述】:
如何将全局变量值从一个函数传递给另一个函数?
我有 2 个全局变量:
$scope.genewtId = null;
$scope.data1 = null;
我有 2 个角函数,如下所示:
$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);
});
};
当我将 $scope.genewtId 的值从一个函数传递到另一个函数时,我得到一个错误
消息:“无法将 'java.lang.String' 类型的值转换为所需类型 'java.lang.Integer';嵌套异常是 java.lang.NumberFormatException:对于输入字符串:“null””
但是,console.log($scope.genewtId); 正在返回一个值 787651,这意味着它不为空。
请建议是否可以使用$rootScope.$broadcast实现
【问题讨论】:
标签: javascript angularjs angular-promise angularjs-service angularjs-http