0

Below this code console.log is working properly. How to set this data another page using another controller.

$scope.selectedJsonObject=function(category)
{
 console.log(category);
}
Brian Tompsett - 汤莱恩
  • 5,438
  • 68
  • 55
  • 126
moni123
  • 165
  • 1
  • 4
  • 12
  • 2
    use a service to communicate between controllers – brk Jul 26 '16 at 07:20
  • http://stackoverflow.com/questions/38563874/how-to-set-first-controller-data-another-controller/38564637#38564637 This is my full question my friend. – moni123 Jul 26 '16 at 07:39

1 Answers1

0

You can use Service to share the variable across two controllers,

angular.module('Shared', []);
angular.module("Shared").factory("myService", function(){
  return {sharedObject: {data: "eran" } }
});
angular.module('Shared').controller('MainCtrl', function ($scope, myService) {
  $scope.myVar = myService.sharedObject;
});
angular.module('Shared').controller('Secondtrl', function($scope, $http, myService) {
  $scope.myVar = myService.sharedObject;
});

Working App

Sajeetharan
  • 203,447
  • 57
  • 330
  • 376