【发布时间】:2016-04-22 18:36:18
【问题描述】:
我有一个名为 readingService 的工厂,工厂方法 GetLastSyncTimestamp 从 Web 服务返回 DateTime,在调用工厂后,我在 $scope.lastSyncTimestamp 变量中分配了返回 DateTime,但问题出在我可以得到的承诺中日期时间正确
readingService.GetLastSyncTimestamp($scope.id).then(function(d) {
$scope.lastSyncTimestamp = d.data;
console.log($scope.lastSyncTimestamp);
});
但在承诺之外我没有得到任何数据
readingService.GetLastSyncTimestamp($scope.id).then(function(d) {
$scope.lastSyncTimestamp = d.data;
});
console.log($scope.lastSyncTimestamp);
有什么方法可以在 promise 之外获取数据?
【问题讨论】:
-
确定使用服务,但问题与 promise 的异步调用有关。当您尝试打印时,实际上没有设置值
-
是的,问题是异步调用,但需要一种方法将其移出
-
使用下面的服务。
标签: javascript angularjs