Skip to main content

Working with $scope.$emit , $scope.$broadcast and $scope.$on

First of all, parent-child scope relation does matter. You have two possibilities to emit some event:
  • $broadcast -- dispatches the event downwards to all child scopes,
  • $emit -- dispatches the event upwards through the scope hierarchy.

  1. If scope of firstCtrl is parent of the secondCtrl scope, your code should work by replacing $emit by $broadcast in firstCtrl:
    function firstCtrl($scope)
    {
        $scope.$broadcast('someEvent', [1,2,3]);
    }
    
    function secondCtrl($scope)
    {
        $scope.$on('someEvent', function(event, mass) { console.log(mass); });
    }
  2. In case there is no parent-child relation between your scopes you can inject $rootScope into the controller and broadcast the event to all child scopes (i.e. also secondCtrl).
    function firstCtrl($rootScope)
    {
        $rootScope.$broadcast('someEvent', [1,2,3]);
    }
  3. Finally, when you need to dispatch the event from child controller to scopes upwards you can use $scope.$emit. If scope of firstCtrl is parent of the secondCtrl scope:
    function firstCtrl($scope)
    {
        $scope.$on('someEvent', function(event, data) { console.log(data); });
    }
    
    function secondCtrl($scope)
    {
        $scope.$emit('someEvent', [1,2,3]);
    }
  4. Use $rootScope.$emit rather than $rootScope.$broadcast regardless of the relationship between trasmitting and receiving controller. That way, the event remains within the set of $rootScope.$$listeners whereas with $rootScope.$broadcast the event propagates to all children scopes, most of which will probably not be listeners of that event anyway. And of course in the receiving controller's end you just use $rootScope.$on.

Comments

Popular posts from this blog

AngularJs call one method of controller in another controller .

I have seen many question about calling one method of one controller in another controller or extending scope of one controller in another controller.so here are the ways. if you want to call one controller into another or extending scope of controllers there are four methods available $rootScope.$emit() and $rootScope.$broadcast() If Second controller is child ,you can use Parent child communication . Use Services Kind of hack - with the help of angular.element() 1. $rootScope.$emit() and $rootScope.$broadcast() Controller and its scope can get destroyed, but the $rootScope remains across the application, that's why we are taking $rootScope because $rootScope is parent of all scopes . If you are performing communication from parent to child and even child wants to communicate with its siblings, you can use $broadcast If you are performing communication from child to parent ,no siblings invovled then you can use $rootScope.$emit HTML <body ng-app = ...

OX Alpha: Nobody Knew Who Made It, and Teams Still Put It in Production

A model called OX Alpha showed up on OpenRouter on August 20. No lab name. No announcement. No documentation beyond a spec sheet: 1,048,576-token context, text and image and video input, function calling, free to use until August 27. Within 24 hours, people were routing production traffic through it. The benchmark claim driving that adoption: 80% on DeepSWE Pass@1. For context, the numbers being passed around put Claude Fable at 65% and GPT-5.6 Sol at 52%. Those numbers came from a ten-task community test, not an audited leaderboard, but that didn't slow anyone down. I'm not here to litigate whether OX Alpha is actually better at coding. I'm more interested in what happened to people's due diligence. What "Stealth" Actually Means on OpenRouter OpenRouter runs a program where labs can preview models anonymously. The provider shows up as "Stealth," and the model name is whatever the lab chooses. The idea is straightforward: labs get real-world ev...

Muse Glimmer: Apache 2.0, 30B, and Why the EU AI Act Just Made Your Model License a First-Class Decision

Meta shipped Muse Glimmer on August 10, and the thing that matters most isn't the benchmark scores. It's the license. After more than a year of closed models, Meta put a 30B parameter agentic model on Hugging Face under Apache 2.0 with no strings attached. That decision landed two weeks after the EU AI Office gained actual enforcement teeth over general-purpose AI model providers. The timing isn't coincidental. What You're Actually Getting Muse Glimmer is a 30B model distilled from Muse Spark. The distillation kept the agentic capabilities, the multi-step reasoning, and the function-calling quality while cutting the parameter count to something you can deploy locally without a data center. At full precision, 30B needs north of 55 GB of memory. In 4-bit K-Quant, the footprint drops to 17-20 GB. A single RTX 4090 or RTX 3090 (both 24 GB) handles it with room left for the KV cache. On a Mac with an M4 Max or M5 Max you have even more headroom. Meta built DFlash specul...