0

I'm trying to pass some data from a selectbox from one controller to another page with different controller in Angular, but I can't seem to get it working. Could some one help me with this?

This is the selectbox with the DataCtrl:

<div class="searchbox" ng-controller="DataCtrl">
  <div class="plumber-by-city col-sm-12 home-text-col">
   <select ng-model="selectedItem" ng-change="change()" ng-options="item as item.city for item in items"></select><span class="fa fa-caret-down"></span>
  </div>
</div>

On change I am taking the value from the selectbox and placing it into $rootScope:

$scope.change = function() {
  $scope.type = $routeParams.type;
    console.log($scope.type);
  $rootScope = $scope.selectedItem.city;
    console.log($rootScope);
};

In the second controller I am trying to get the data from $rootScope and use it there but is not working

app.controller('DataCtrl2', function($rootScope,$scope,$http) {
  $scope.selectedItem.city = $rootScope.selectedItem.city;
  console.log($rootScope.selectedItem.city);
});
eko
  • 39,722
  • 10
  • 72
  • 98
Larsmanson
  • 413
  • 1
  • 5
  • 18
  • 1
    Possible duplicate of [Share data between AngularJS controllers](https://stackoverflow.com/questions/21919962/share-data-between-angularjs-controllers) – anoop Jun 13 '17 at 14:57
  • 1
    avoid `$rootScope`, use `service\factory` instead. – anoop Jun 13 '17 at 14:59

0 Answers0