Reputation: 151
This is the view code:
<a type="button" ui-sref="index.usermng.userInfo" ng-click="checkUserInfo(item.id)" class="btn btn-primary">check</a>
Controller:
//UserManage Controller
userApp.controller('userCtrl', ['$scope', '$http', '$location', 'serverUrl', function($scope, $http,
$scope.checkUserInfo = function(userId) {
console.log(userId);//I can get userId in here
$scope.$broadcast('toUserInfo',userId);
}
}]);
//UsrInfo Controller
userApp.controller('userInfoCtrl', ['$scope', '$http', 'serverUrl', function($scope, $http, serverUrl) {
$scope.$on('toUserInfo',function(data){
console.log("in.....");
console.log(data);
})
How to get the 'userId' from 'userCtrl' in 'userInfoCtrl'?
Upvotes: 0
Views: 38
Reputation: 4147
Using rootScope to communicate between controllers
userApp.controller('userCtrl', ['$scope', '$http', '$rootScope',
function($scope, $http,$rootScope) {
$scope.checkUserInfo = function(userId) {
console.log(userId);//I can get userId in here
$rootScope.$broadcast('toUserInfo',userId);
}
}]);
Now the userInfoCtrl
can get the userId
from userCtrl
.
Upvotes: 1