$stateProvider.state( 'clientinfo', {
abstract: true,
url: '/clientinfo',
resolve: {
clients: ['Restangular','localStorageService',function(Restangular,localStorageService){
var clients = localStorageService.get('clients');
if(clients == null) {
return Restangular.all('clients').getList().then(function(result){
localStorageService.add('clients',result);
angular.copy(result, clients);
});
return clients;
}]
}
......
}
我尝试使用 localStorage 和 restangular,但在初始页面加载时,我的客户端对象没有返回实际的 GET 响应,而是返回一个空对象,尽管我的本地存储设置正确。
此代码在没有本地存储的情况下按方面工作:
$stateProvider.state( 'clientinfo', {
abstract: true,
url: '/clientinfo',
resolve: {
clients: ['Restangular',function(Restangular){
return Restangular.all('clients').getList();
}
}
.....
}
有什么帮助吗?谢谢
我将此模块用于本地存储:https ://github.com/grevory/angular-local-storage Restangular:https ://github.com/mgonto/restangular