Reputation: 11198
I have two views and I use routes to access them. My main view is a list that uses ListController
.
That controller does an $http
request and gets some data back and on success
I do: $scope.data = response.data;
When I click on a list item, my route goes to #/view/:id
I am able to get the id
using routeParams
in my other controller: DetailController
Since $scope.data
was part of the ListController
, how do I access say $scope.data
in my DetailController
?
(or at least pass $scope.data[some Id]
to DetailController
)
EDIT
app.factory('dataService', function(data)
{
var data = data;
return data;
});
the answer was to place this in my DetailController
. response.data
was still available to me
presentationService().then(
function success(response)
{
log(response.data);
},
function error(response)
{
log(response);
}
);
Upvotes: 1
Views: 369
Reputation: 8716
You should not use scopes for sharing data between controllers. Use service instead. Watch this short movie: http://egghead.io/video/angularjs-sharing-data-between-controllers/
Hope it helps.
Upvotes: 2