现在我有一个加载器页面,我做一些请求。
function PeopleController($scope,$http,$location){ $http.get('/location/-79.18925/43.77596'). success(function(data){ $scope.savePeopleResponse(data); $location.url('/test'); }); }
然后在视图中为/ test加载
我只是打电话
<div ng-controller="resultController"> <div class="blueitem">{{getResultForPeople()|json}}</div> </div>
[resultController]
function resultController($scope){ $scope.getResultForPeople = function(){ return $scope.getPeopleResponse(); } }
并且savePeopleResponse和getResultForPeople在rootScope中被“缓存”
app.run(function($rootScope) { var peopleResponse = {}; $rootScope.savePeopleResponse = function(data) { peopleResponse = data; console.log(data); } $rootScope.getPeopleResponse = function(){ return peopleResponse; } });
现在你可以看到,如果这个应用程序越来越大,这将变得非常混乱。什么是处理数据的最佳方式,以便其持续存在于控制器?