Это код вида:
<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);
})
Как получить "userId" из "userCtrl" в "userInfoCtrl"?
Использование 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
.
data
в$on
?