Answer the question
In order to leave comments, you need to log in
How to correctly pass a variable between controllers in AngularJs via $rootScope.$broadcast?
Tell me how to correctly pass a variable to AngularJs via $rootScope.$broadcast?
I try like this:
.controller('ctrl1', function($scope, $rootScope) {
// ...
$scope.funEvent = function(id) {
$rootScope.$broadcast("results", id);
};
})
.controller('ctrl2', function($scope, $rootScope) {
$rootScope.$on("results", function(event, id) {
$scope.results = id;
console.log(id);
});
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question