AngularJs broadcast event

后端 未结 2 2036
小蘑菇
小蘑菇 2021-01-26 07:41

I want to broadcast angular event from javascript function i.e angular.injector([\'ng\', \'myModule\']).get(\"mySharedService\").prepForBroadcast(\'hello\'); By using above line

2条回答
  •  清酒与你
    2021-01-26 07:52

    Another way of publishing events from one controller and listening them in other controllers would be to use angular-PubSub module.

    The PubSub makes only subscribers to listen to the published events unlike the $rootScope.$broadcast in which it sends event to all the Scopes in Scope hierarchy making it inefficient as compared to the PubSub approach.

提交回复
热议问题