0

在名为的控制器下,usersConrtoller.js我将一些对象数据存储在localStorageusing 中ngStorage

$scope.users = [{
        "entity$": "-/sys/daily_journeys",
        "name": "Tom",
        "walked": 90,
        "traveled_distance": "773",
        "total_cout": 0.367,
        "days": 22,
        "avg_risk": "0.0",
        "risk_category": "GREEN"
}]

保存到本地存储:

$localStorage.users = $scope.users;

如何$localStorage.users在其他控制器中访问对象的数据?

4

1 回答 1

1

据我所知,这ngStorage是一个可注入的服务,所以在其他控制器中你只需要注入服务并阅读它

$scope.users = $localStorage.users

或者您可能需要监视它以查看它是否已更新

$scope.$watch(function(){
  return $localStorage.users
}, function (users) {
  $scope.users = users;
})
于 2015-06-21T20:02:27.387 回答