这是视图代码:
<a type="button" ui-sref="index.usermng.userInfo" ng-click="checkUserInfo(item.id)" class="btn btn-primary">check</a>
控制器:
//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);
})
如何从'userInfoCtrl'中的'userCtrl'获取'userId'?
答案 0 :(得分:1)
使用rootScope在控制器之间进行通信
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);
}
}]);
现在userInfoCtrl
可以从userId
获得userCtrl
。