I am making a website based on MEAN. Now I am trying to pass data from one controller to the next, but I don't seem to get it done. When an option is selected I want to take this value to the next page
This is the page with the selectbox:
<div class="plumber-by-city col-sm-12 home-text-col" ng-controller="DataCtrl">
<div class="title-1">Search by cityname</div>
<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>
On change I want to take the selectedItem passed through to the next page with DataCtrl2
This is my DataCtrl:
app.controller('DataCtrl', function($scope,$http,getData,$location,$routeParams){
getData.getCity($scope);
$scope.change = function() {
$location.path('/plumber-in/' + $scope.selectedItem.city);
};
});
And the service that retrieves data from DB:
app.factory('getData', function($http){
return {
getCity: function($scope){
return $http.get("/getdata").then(function(response){
$scope.items = response.data;
$scope.selectedItem = response.data[0];
});
}
};
});
Now I don't know what to put in the DataCtrl2 for the second page and how to use the data from the DataCtrl in this page