如果存在,我想从localStorage获取对象公司 把它返还 并转到服务器并更新localStorage中的公司
如果localStorageCompanies为空,我需要订阅谁 叫做 函数来从服务器获取结果,热点我做了吗?
以及我如何执行此代码:
localStorage.setItem('companies',JSON.stringify(res.result));
在此代码之后:
if(!localStorageCompanies){
return res;
}
getCompanies(): any {
const localStorageCompanies = localStorage.getItem('companies');
this.http.get(environment.apiUmbracoUrl+'home/GetCompanies').subscribe(
res => {
//this.sharedService.turnOnLoader();
if(res.rc == 0){
localStorage.setItem('companies',JSON.stringify(res.result));
if(!localStorageCompanies){
return res;
}
}
});
if(localStorageCompanies){
return {rc:1,result:JSON.stringify(localStorageCompanies)};
}
}