我有 2 个控制器 FirstController、SecondController 和如下服务:
app.factory('Data', function(){
return [];
});
我将服务用于两个控制器,如下所示:
app.controller("FirstController", function($scope, $http, Data) {
// getting an JSON array using $http.get() and storing it into Data.myArray for example
}
app.controller("SecondController", function($scope, $http, Data) {
// I want to do something like this, to recover the array from the Service
$scope.recoveredArray = Data.myArray;
// then do stuff to the reoveredArray...
}
最后显示从 SecondController 到 html 视图的recoveredArray。
非常感谢您提前。