我有一個工廠名爲readingService
的工廠方法GetLastSyncTimestamp
從Web服務返回一個DateTime,調用工廠之後我已經在$scope.lastSyncTimestamp
變量中分配了返回DateTime,但是問題出現在promise中我可以得到日期時間正確訪問外界承諾的angularjs工廠數據
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);
有沒有辦法到外面的承諾獲取數據?
確定使用服務,但問題與承諾的異步調用有關。當你嘗試打印的值實際上沒有設置 – thegio
是的問題是異步調用,但需要一種方式來獲得它 – Mostafiz
使用下面的服務。 – thegio