我的工厂看起来像这样:
MyApp.factory("Hello", function(Restangular, $q){
var theConfig = function() {
var deferred = $q.defer();
Restangular.one('AllSettings').get().then(function(data){
var theData = return {
config1: data.config1,
config2: data.config2
}
deferred.resolve(data);
});
return deferred.promise;
};
return{
config : theConfig()
};
});我已经使用了deffered,但它仍然没有返回需要执行的对象。如何解决这个问题?
发布于 2013-10-28 01:05:52
您返回的是一个promise,而不是传递到deferred.resolve的实际数据。您是否像这样访问数据?
MyApp.controller('WhateverController', function(Hello) {
Hello.config.then(function(data) {
// Do something with the data passed to deferred.resolve
});
});https://stackoverflow.com/questions/19619927
复制相似问题