Question

I have 2 partial pages in angularjs single page application. In page 1 I take input from user as ngModel and on next button click based on that i show someimage in next partial page. If User likes it there is option to save the current model data but on this page I don't have ngModel. How can i access model object on 2nd partial page submission?

Was it helpful?

Solution 2

You can use a service like

angular.module("myApp",[]).service("MyService",function(){return {myValue:{}})

or you could use angular value

angular.module("myApp",[]).
  value("myValue", {}).
  controller("MyCtrl1", function($scope, myValue){
    $scope.someValue = myValue;
  }).
  controller("MyCtrl2", function($scope, myValue){
    $scope.someValue = myValue;
  })

or you could use $routeParams to pass the value if it's an id or the like.

OTHER TIPS

To share some data between page transitions you can simply use $cacheFactory service.

Another more straightforward way is to save data to $rootScope.
All controller scopes is inherited from the root scope, so you can save some data to $rootScope variable on first page and then access it via $scope on next page.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top