Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Web Technology by (47.6k points)

I have a footerController and codeScannerController with different views.

angular.module('myApp').controller('footerController', ["$scope", function($scope) {}]); angular.module('myApp').controller('codeScannerController', ["$scope", function($scope) { 

console.log("start"); $scope.startScanner = function(){...

When I click on a <li> in footer.html I should get this event in codeScannerController.

<li class="button" ng-click="startScanner()">3</li>

I think it can be realised with $on and $broadcast, but I don't know how and can't find examples anywhere.

1 Answer

0 votes
by (106k points)

You should use the $rootScope if you want to $broadcast:-

$scope.startScanner = function() { $rootScope.$broadcast('scanner-started'); 

}

After that to receive, use the $scope of your controller:-

$scope.$on('scanner-started', function(event, args) { 

// do what you want to do 

});

Related questions

0 votes
2 answers
+2 votes
1 answer
+2 votes
1 answer
0 votes
1 answer
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...