controller - angularjs passing scope between routes -


i want :

1. set $scope.val = <some dynamic data>  2. click link , routed new template (with same controller).  3. $scope.val should still same value on last page. 

is somehow persisting data scope right way go this, or there other way? can create controller has persisted scope between routes, except saving in database of course.

you can share data between controllers not simple $scope.

you can use services task.

a controller gets recreated whenever access new route. service singleton in app. data stored in service can accessed every new controller.

your service can simple , return empty object:

app.factory('shareddata', function() {   return {     name: 'daniel'   }; }); 

then in controller can simple set data object service $scope.

app.controller('maincontroller', function($scope, shareddata) {   $scope.data = shareddata; }); 

here working plunker


Comments