作者:太阳神神神_890 | 来源:互联网 | 2024-10-12 13:40
1234567891011121314151617 mainModelHttpService.getHttpGetMainCountModelPromise("", "").success(funct
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| mainModelHttpService.getHttpGetMainCountModelPromise("", "").success(function(response) {
$scope.Data = [{
value: response.Register,
name: '注册'
}, {
value: response.Using,
name: '使用中'
}, {
value: response.Fault,
name: '故障'
}, {
value: response.Scrap,
name: '报废'
}];
console.log( $scope.Data);//这里可以打印出来
});
console.log($scope.Data); //undefined |
现在很纳闷,请求到的数据是挂到了$scope上,为什么在这个服务外获取不到呢?
应该怎么做才能获取到呢 因为这些数据是在后面指令中要用的
下面是我在服务中封装的$http请求
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| var httpGetMainCount = function(start, end) {
var deferred = $q.defer();
$http.get("/statistic?start=" + start + "&end=" + end).success(function(response) {
var temp = response.Data;
deferred.resolve(temp);
}).error(function(e) {
var errMsg = e.Message || e.ErrMsg || e;
deferred.reject(errMsg);
});
return deferred.promise;
};
var getHttpMainCountModelPromise = function(start, end) {
httpGetMainCount(start, end);
return httpGetMainCountPromise;
}; |
这样写的话控制台一直报success of undefined