次のように、FirstController、SecondController、およびサービスの2つのコントローラーがあります。
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...
}
最後に、RecoveredArray を SecondController から html ビューに表示します。
事前にどうもありがとうございました。