我的工廠代碼無法從工廠返回值服務angularJS
.factory('appData', ['connectionManager', function($connectionManager) {
return {
getAppDataItem: function(apiName, params) {
console.log('Getting value...');
$connectionManager.sendRequest({
'apiName': apiName,
'params':{
'@key': "'" + params['@key'] + "'"
}
}).then(function(res){
console.log('Retrieved data ', res.data);
return res.data;
});
}
}
}]);
我的服務代碼
var x = appData.getAppDataItem('getItemFromAppData', {
'@key': 'last_emp_id'
});
console.log(x);
我想通過.then()
工廠返回的值賦給var x
在我的服務。但我無法做到。請幫幫我。我的價值高達.then()
。之後,我無法將其傳遞給服務。
你有什麼錯誤嗎? apiName是否清楚傳遞? – Aravind
可能的重複[如何返回來自異步調用的響應?](http://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call) –