0

I have a function to filter state based on user click on state list.

This is the table controller:

.controller('TableController', ['$rootScope', '$scope', '$http', 'Table', '$stateParams', '$filter', '$window',
function ($rootScope, $scope,$http, Table, $stateParams, $filter, $window) {

    $scope.filterState = 'All';
    $scope.getState = function(value){
        $scope.filterState = value.state;
        $scope.FilterStateFunction = {
            State: value.state
        };
        var param = value.state;
        alert(param); //it does alert 'New York'
        $rootScope.$emit("CallParentMethod", function(param){});
    }
])

This is the maps controller:

.controller('MapsControllerCompleted', ['$rootScope', '$scope', '$http', 'Maps', '$stateParams', 
function ($rootScope, $scope, $http, Maps, $stateParams) {

     $rootScope.$on("CallParentMethod", function(param){
        alert(param); //however it displays [object Object] instead of 'New York'
     });

})

And this is the html:

    <div class="container">
        <ul class="nav nav-tabs">
            <li class="active"><a href="#All" target="_self" data-toggle="tab" ng-click="getState({ state: 'All' })">All </a></li>
            <li class="{{ (filterState == state)? 'active' : '' }}" ng-repeat="state in distinctState"><a href="#{{ state | removeSpace }}" target="_self" data-toggle="tab" ng-click="getState({ state })">{{ state }} </a></li>
        </ul>
    </div>

When I click on the <li>, it will call getState function and I want to pass the value of state selected as a param variable from table controller to maps controller.

I tried to alert the param on table controller, it does display the state, e.g.: New York. However, when I passed the param inside CallParentMethod it does not alert the New York but an [object Object].

Any ideas how to pass value from one controller to another?

Thank You.

avdnowhere
  • 177
  • 2
  • 16

0 Answers0