Angularjs的计时问题检索值和显示



嗨,在我的控制器我有以下代码,从数据库获取数据。它正确地获取数据,没有问题,因为我可以在firebug中看到它。

 $scope.up = supRepository.getPrice.query({ id: sup._id }, function(data) {
                $scope.up = data;
            });
            alert($scope.up.description);

问题是,在警报时,它只给我一个空盒子,里面什么也没有。无错误或值。我认为这可能与时机有关?请让我知道我该如何修理它。因此,如果是计时问题,它将等待,直到这些值可用。由于

您需要将警报移动到回调中,以便您知道您已经收到了data

supRepository.getPrice.query({ id: sup._id }, function(data) {
      $scope.up = data;
      alert($scope.up.description);
});

最新更新