2

I am novice in AngularJS. I was trying to send an object from one controller to another using $routeParams.

$location.path("/addMyResults/"+JSON.stringify($scope.resultsObj));

This is how i am routing:

$routeProvider
.when('/addMyResults/:myresultsObj',{
    templateUrl : 'partials/myResultsAdd.html',
    controller : 'AddMyResultsController'
});

and collecting the object in another controller as:

$scope.resultsObj = angular.fromJson($routeParams.resultsObj);

The resultsObj has two string properties name & address. When '/' is entered into the address string(infact any field) the routing does not work.

Please let me know if there is some solution.

Community
  • 1
  • 1
AUK4SO
  • 301
  • 2
  • 13
  • You should create an service to deal with data in multiple controllers.But you're able to put your object to `$rootScope` which can be accessed from everywhere. https://docs.angularjs.org/api/ng/service/$rootScope – gearsdigital Sep 23 '14 at 17:57
  • Examples over here: http://stackoverflow.com/questions/18880737/how-do-i-use-rootscope-in-angular-to-store-variables – gearsdigital Sep 23 '14 at 17:58

1 Answers1

-1
'/addMyResults/:myresultsObj',
Shahbaz A.
  • 4,047
  • 4
  • 34
  • 55