0

I have 2 controllers and one service.From one controller calling service and result $emit to another controller in another page .but its not working.Please help.Thanks in advance.

In first controller

routerApp.controller('DetailCtrl',['$scope''ChefService','$rootScope',function($scope,ChefService,$rootScope){
   $scope.Fn_ClickChefProfile = function(chefid){
    ChefService.GetChefProfile(chefid).then(function(d){
    $rootScope.$emit("CallToChef",d);
     });};]});

In second controller

routerApp.controller('ChefCtrl',['$scope','$rootScope','ChefService',function($scope,$rootScope,ChefService){

$rootScope.$on("CallToChef",function(event,data){
  $scope.Fn_GetChefProfile(data);
 });
 $scope.Fn_GetChefProfile = function(data){
console.log(data);
 };}]);
Rahul K R
  • 191
  • 4
  • 20
  • sorry, another controller **in another page**? Like you have two copies of the app running in different browser windows? – Claies Nov 30 '16 at 18:55

1 Answers1

0

Take a look at this answer

$emit dispatches an event upwards (to parent controller) ... $broadcast dispatches an event downwards (to child controller)

Community
  • 1
  • 1
nlarche
  • 132
  • 7