0

my very first post here and feels great.

At the moment i have a controller that get my JSON data and puts it in the scope.hotels.

app.controller('ListController1', function($scope, $http){
  $http.get('js/hotels1.json').success(function(data){
    $scope.hotels = data;
  });
});

Nothing fancy here but as far as i know, my second controller cant reach $scope.hotels. Here is my 2nd controller

app.controller('BookCtrl', function($scope, $state){
  $scope.Id = $state.params.Id;
})

How would i go about doing this?? Thanks alot!

Pappsen
  • 31
  • 2

2 Answers2

0

Generally, you shouldn't use ajax calls inside controllers. But rather call services that does this. You can then also save this state in service, and since it is singleton, injecting it in any other controller will give you the same data.

obey
  • 796
  • 7
  • 16
0

Define one controller as Parent in html. Then use $scope.$broadcast from the parent and catch it in the child controller with $scope.$on. Read up on these methods from angular docs. Cheers

Risalat Zaman
  • 1,189
  • 1
  • 9
  • 19