how to emit events from a factory

后端 未结 3 2034
时光取名叫无心
时光取名叫无心 2020-12-14 15:17

How can I emit events from a factory or service. I am unable to inject $scope into the factory, thus unable to emit events.

I get the following error - Unknow

3条回答
  •  猫巷女王i
    2020-12-14 16:08

    In your factory inject $rootScope as-

    myApp.factory('myFactory',function($rootScope){
    return({
    // use $rootScope as below to pass myEventParams to all below in hierarchy
    $rootScope.$broadcast("myEvent",myEventParams);
    
    })
    }]);
    

提交回复
热议问题