AngularJS: 'Collector' service returns promise; how to resolve within function to still pass value?

I've written a service Collector to store my models, which interfaces with localStorage and my server. I have a function Collector.retrieveModel(uuid) which retrieves a model from the collector, first checking localStorage to see if it is already extant, otherwise requesting it from my server.

Here's what it looks like:

var retrieveModel = function(uuid) {
    var deferred = $q.defer();
    var promise = deferred.promise;

    if (typeof uuid === 'undefined') {
        console.log("retrieveModel called without param");
        deferred.resolve( collector );
    }

    if ( collector[uuid] = localStorage.getItem(uuid) ) {
        //object was in local storage, return the data

        **Problem is somewhere around here**

        deferred.resolve( collector[uuid] );

    } else {
        //doesn't exist in collector, request it
        //remoteModel is a wrapper function, which itself returns a promise, which is resolved upon a successful call using $resource
        remoteModel(uuid).then(function (val) {
            deferred.resolve(val);
        });
    }

    return promise;
};

As it currently exists, it the model was not present in localStorage (and remoteModel is called) the promise is returned, and fulfilled once the model is retrieved from the server. subsequently, the relevant $scopes are updated. This works as expected.

However, when the model is present in localStorage, then the deferred is resolved, but before the function returns a promise. Thus, the resolved value is never propagated.

What can I do to consistently return a promise, but not fulfill it prematurely? I don't want to use $timeout.

I think you're very close; on mobile so I can't test right away but I think if you resolved your promise inside a .then() callback you'd get the desired result. Something to the effect of:

deferred.promise.then(function () { 
  deferred.resolve( collector[uuid] ); 
})  

The idea being you want to wait until the function returns the promise, invokes the then() in which you resolve your local storage response.