我需要在下面的函數中打印出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
你爲什麼要在功能外打印? –