Angularjs 延迟。通知未到达目的地

Angularjs 延迟。通知未到达目的地,angularjs,promise,angular-promise,deferred,Angularjs,Promise,Angular Promise,Deferred,我有一个指令,它使用服务获取一些数据。该服务尽可能使用缓存 如果数据在缓存中,notify可以正常工作。但是,当第一次获取数据时,会触发通知,但通知似乎未到达目标 我花了一段时间研究它,不知道出了什么问题。希望这只是个简单的错误 指令 kitchenApp.directive( 'chunkViewer', [ 'v10systemModel', function(v10systemModel) { return { link: funct

我有一个指令,它使用服务获取一些数据。该服务尽可能使用缓存

如果数据在缓存中,notify可以正常工作。但是,当第一次获取数据时,会触发通知,但通知似乎未到达目标

我花了一段时间研究它,不知道出了什么问题。希望这只是个简单的错误

指令

kitchenApp.directive(
'chunkViewer',
[
    'v10systemModel',
    function(v10systemModel) {
        return {
            link: function($scope, element, attrs) {
                // attrs are all lower-case
                $scope.chunkID  = attrs.chunkid;
            },
            controller: function($scope) {
                v10systemModel.fetchDocument($scope.state.systemID, $scope.state.bookID)
                    .then(null, null, function(doc) {
                        $scope.chunk = doc.getChunkContents($scope.chunkID);
                    });
            },
            templateUrl: '/views/v10/directives/chunk-viewer.html',
        };
}]);
服务(部分)


为什么使用
notify
而不是
resolve
?此外,如果该
返回deferred.notify(docObject)
contain
return
?我正在使用notify,因为此链末尾的数据源可能随时更新@tanmay@axzr我不确定是否有人知道这意味着什么,但我不知道。你能解释清楚一点吗?进度通知是承诺中很少使用的一部分,从上面的代码中,我看不出为什么在这里使用
.notify
是有意义的。看来你可能走错方向了。@JLRishe-喊得好。我正在使用notify,因为数据库可能会在我的“下方”更新。我正在使用Firebase作为后端,我正在观察它的更新。当一个通过时,我想更新视图。这能更好地解释吗?为什么使用
通知
而不是
解决
?此外,如果该
返回deferred.notify(docObject)
contain
return
?我正在使用notify,因为此链末尾的数据源可能随时更新@tanmay@axzr我不确定是否有人知道这意味着什么,但我不知道。你能解释清楚一点吗?进度通知是承诺中很少使用的一部分,从上面的代码中,我看不出为什么在这里使用
.notify
是有意义的。看来你可能走错方向了。@JLRishe-喊得好。我正在使用notify,因为数据库可能会在我的“下方”更新。我正在使用Firebase作为后端,我正在观察它的更新。当一个通过时,我想更新视图。这能更好地解释吗?
service.fetchDocument = function(systemID, docID) {
    var deferred = $q.defer();

    if (systemID === cachedSystemID && docID === cachedDocID) {
        $timeout(function() {
            //
            // this one works
            //
            deferred.notify(cachedDoc);
        });
        return deferred.promise;
    }

    if (cachedDocID) {
        v10firedocs.stopWatchingDocument(RPGS_COLLECTION, cachedSystemID, cachedDocID);
        cachedSystemID = cachedDocID = cachedDC = null;
    }

    v10firedocs.getDocument(RPGS_COLLECTION, systemID, docID)
        .then(null, null, function(docObject) {
            cachedDoc = docObject;
            cachedSystemID = systemID;
            cachedDocID = docID;

            //
            // this doesn't appear to work
            //
            return deferred.notify(docObject);
        });

    return deferred.promise;
};