数据我想从$http.then
函数返回值:如何返回从http sucess功能
if(navigator.onLine){
$http({
method:'GET',
url:url,
}).success(function(data, status){
localStorage.setItem('abc', JSON.stringify(data));
}).then(function(){
return JSON.parse(localStorage.getItem('abc'));
});
}else{
return JSON.parse(localStorage.getItem('abc'));
}
我能够从else
块获取JSON数据,但是从then
功能越来越null
值。
而这个功能是在一个服务里面。
当我安慰的回报,我得到'对象{数据:对象,状态:200,headers:function,config:Object}' – Anenth
@第十一:啊,听起来很合理。与'success'回调多个参数不同,'$ http'允许产生一个对象,我们只对'.data'属性感兴趣。调整我的答案。 – Bergi
okey明白了! 'data.data.abc'获取数据 – Anenth