2017-03-14 9 views
0

まずコントローラー:

$rootScope.$broadcast("CallParentMethod", {});

第二コントローラー:

$rootScope.$on("CallParentMethod", function() { 
    $scope.getUserDetails(); 
}) 
$scope.getUserDetails = function() { 
    HttpService.get("/customer/" + nationalId).then(function(resp) { 
     if (resp.status == 'success') { 
      console.log(resp.result) 
      $rootScope.county_name = angular.copy(resp.result.county) 
      $rootScope.campaign_name = angular.copy(resp.result.campaign) 
      console.log($rootScope.campaign_name) 
     } 
    }); 
}; 
+0

は、作業コードsnippを提供するとき、あなたは空のオブジェクト{}を無視することができますet。 [MCVE]をお読みください – Gaurav

答えて

0

$scopes

のミックスがあります。このイベントがあるがゆえ、あなたがする必要があります

$rootScope.$broadcast("CallParentMethod", {}); 

を解雇しましたlあなたは

$scope.$on("CallParentMethod", function() { 
    $scope.getUserDetails(); 
}) 

別に定義されているgetUserDetails()に同じスコープでそれをリッスンすることがあります子$スコープで、このイベントのためにisteningが、あなたは$rootScope

$rootScope.$on("CallParentMethod", function() { 
    $scope.getUserDetails(); 
}) 

でそれを聴いていますヒント:あなたは任意のパラメータを渡す必要がない場合$broadcasting

$rootScope.$broadcast("CallParentMethod") 
関連する問題