I'm currently working on an angular app in which I have a service returning data from a $http request.
我目前正在开发一个角应用程序,其中我有一个从$http请求返回数据的服务。
To reduce http requests, I'm storing a large amount of data ( 100-300 ) results per search.
为了减少http请求,我在每个搜索中存储了大量的数据(100-300)。
I have three Controllers:
我有三个控制器:
- holds my filters (sliders, checkboxes etc)
- 保存我的过滤器(滑块,复选框等)
- holds my list of items
- 保存我的物品清单。
- holds a google map which shows the markers of all the returned results.
- 持有一个谷歌地图,显示所有返回结果的标记。
Im trying to filter the array in controller one and update this accross for controller two and three. So ideally all three controllers are watching and using the same array.
我试图在控制器1中过滤数组,并更新控制器2和3。理想情况下,所有三个控制器都在观察和使用相同的数组。
Can anyone help, is this even possible ?
有人能帮忙吗,这可能吗?
1 个解决方案
#1
0
Store your array in the $rootScope This is a global scope that can be accessed from all others controllers.
将数组存储在$rootScope中,这是一个全局范围,可以从所有其他控制器访问。
angular.module('App').controller('OneController', [
'$scope', '$rootScope', function($scope, $rootScope) {
$scope.propertiesForThisScope = 123;
$rootScope.theArray = [];
}]);
#1
0
Store your array in the $rootScope This is a global scope that can be accessed from all others controllers.
将数组存储在$rootScope中,这是一个全局范围,可以从所有其他控制器访问。
angular.module('App').controller('OneController', [
'$scope', '$rootScope', function($scope, $rootScope) {
$scope.propertiesForThisScope = 123;
$rootScope.theArray = [];
}]);