How to pass parameter between different controller


#1

Hi,
I am new to mobile development i am trying to pass parameter between two controllers. Refer the below code.

HTML
**>

    <ion-content class="padding">
    </br>
    </br>
    </br>
    <div  ng-controller="ClickCtrl">
    <div class="row" ng-repeat ="item in current.data" >
                    <div class="col"><B  class="col dark" >{{item.status}}</B></div>
                    <div class="col">{{item.count}}</div>
                    <div class="col"><button class="button button-outline button-energized"  ng-click="statusData(item.status)" >Go..</button ></div>
    </div>
    </div>
</<ion-content>
  </ion-view>**

APP.js

angular.module(‘starter’, [‘ionic’,‘ngResource’, ‘starter.controllers’, ‘starter.services’])

.config(function($stateProvider, $urlRouterProvider) {
$stateProvider
.state(‘tab.facts’, {
url: “/facts”,
views: {
‘tab-home’: {
templateUrl: ‘templates/facts.html’,
controller:‘StatusCtrl’
}
}
})
//Controller.js
controller(‘ClickCtrl’, function($scope, $state, userService) {

$scope.statusData = function(st) {

alert(st);// i am getting this value…
$scope.st=st;
$state.go(‘tab.facts’);

}
})

.controller(‘StatusCtrl’, function($scope,$state, userService) {

alert($scope.st); //I need the status here

//call getCurrentWeather method in factory ‘Weather’
userService.getStatusRecords($stateParams.statusData).then(function(resp) {
alert(‘success’);
$scope.current = resp;

}, function(error) {
  alert('inside error order');
  console.error(error);
});

})


#2

Hi this is really an Angular specific question rather than Ionic. But to answer your question - you should use an Angular service or even broadcast/listen.

https://docs.angularjs.org/guide/services

And here is an example on StackOverflow