2016-12-14 2 views
0

Ich sende derzeit einen untergeordneten Bereich (von einem übergeordneten Controller zu einem untergeordneten Controller). Im $ scope. $ Auf

app.controller('myCtrl') 

    $scope.$on('broadcastName', function(e, d){  
     //I want to be able to access myCtrl's scope here even though 
     //the broadcast comes from another controller 
    }); 

Ich mag Zugriff auf den aktuellen Controller Umfang haben, der die Sendung mit in meinem $ scope fängt. $ Auf Funktion, nicht die übergeordnete Steuerung, die die Sendung emittieren.

Ich dachte mir die Antwort aus, als ich die Frage aufschrieb.

Antwort

0

Ich hoffe, das spart jemand anderes einige Zeit

app.controller('myCtrl') 

$scope.$on('broadcastName', function(e, d){ 
    /* if you want the scope of the controller that made the broadcast */ 
    console.log('parent scope', e.targetScope); 
    /* if you want the scope of the controller that caught the broadcast it is just your basic scope */ 
    console.log('child scope', $scope); 
}); 
Verwandte Themen