我是AngularJS的新手,我卡住了:\ NEED HELP,please!
下面的代码的目的是从数据库中获取一个特定的数据(一个整数),以建立一个圆环图。 我运行函数dataforGraphs()以获取该值。但是,在功能之外,我“放弃”了这个价值。
(代码时,我提出的意见,以更好地解释情况)
uONEControllers.controller('HomeCtrl', ['$scope', 'GraphService',
function ($scope, GraphService) {
var ammountOfFinishedOrders = {};
dataforGraphs(); // calling the function
function dataforGraphs() {
GraphService.getAmmountOfFinishedOrders()
.success(function (data) {
$scope.ammountOfFinishedOrders = data.GetAmmountOfFinishedOrdersResult;
//this console.log shows me the value 3. Excellent!
console.log("value 1:", $scope.ammountOfFinishedOrders)
})
.error(function (error) {
$scope.status = 'Unable to load data:' + error.message;
});
//HOWEVER... here is undefined
console.log("value 2:", $scope.ammountOfFinishedOrders)
};
//here, outside the function, too :(
console.log("value 3:", $scope.ammountOfFinishedOrders)
//building the doughnut graphic
$scope.labels = ["January", "February", "March", "April", "May", "June", "July"];
//THE PROBLEM IS HERE. The $scope.ammountOfFinishedOrders is undefined! WHY??
$scope.data = [
$scope.ammountOfFinishedOrders, 4, 1, 3, 2, 1, 4
];
}]);
我已经尝试返回$ scope.ammountOfFinishedOrders,但仍然一无所获。这可能是范围继承问题吗?如果是的话,我应该怎么做才能解决这个问题?如果没有...好吧,无论如何帮助我:D
非常感谢!
哈哈,你通过1:40秒打我:P – squiroid
哈哈哈哈。每个人都在线。 :P – nikhil
谢谢!有效!我现在可以停下来对着电脑碰头了:D我没有意识到异步效应。 再次感谢。 –