我需要在下面的函数中打印出localeData值。 我知道如何在功能方面打印,就像我在这里所做的一样。 我试过这个,但没有工作。Angularjs获取函数外的对象值
$http.post(SERVER_URL + 'getLocaleData').success(function(localeData) {
console.log(localeData);
}).error(function(err) {
alert('warning', err.message);
});
//need to get that value here.
console.log(localeData);
编辑
其实我需要做的就是这个
app.factory('customLoader', function($http, $q, SERVER_URL) {
return function(options) {
var deferred = $q.defer();
// do something with $http, $q and key to load localization files
$http.post(SERVER_URL + 'getLocaleData').success(function(localeData) {
//do something here to localData
}).error(function(err) {
alert('warning', err.message);
});
deferred.resolve(localeData);
return deferred.promise;
};
});
这正是我需要的。最后我需要发送localeData。
你应该把这个输出分配给控制器的对象/变量 – Vineet
任何想法该怎么做? – Mad
你为什么要在功能外打印? –