title: Event namespace for multiple child controllers in AngularJS
body: <p>I am trying to namespace events emitted by multiple child controllers of the same type. The problem is letting the parent know the child id. Consider the following scenario.</p>
  
  <pre><code>&lt;div ng-controller="Parent"&gt;
    &lt;div ng-include="child1"&gt;&lt;/div&gt;
    &lt;div ng-include="child2"&gt;&lt;/div&gt;
    ... and so on, the parent decides which templates to include on the fly
  &lt;/div&gt;
  
  &lt;script type="text/ng-template" id="Child.html"&gt;
    &lt;div ng-controller="Child"&gt;...&lt;/div&gt;
  &lt;/script&gt;
  
  function Parent($scope) {
    $scope.child1 = "Child.html";
    $scope.child2 = "Child.html";
  
    // The problem is setting these
    $scope.childId1 = 1;
    $scope.childId2 = 2;
  
    $scope.on($scope.childId1 + ".someEvent", function() {
      // Handle event from child 1
    });
    $scope.on($scope.childId2 + ".someEvent", function() {
      // Handle event from child 2
    });
  } 
  
  function Child($scope) {
    $scope.id = getNewId();
  
    // Here I would like to do something like
    $parent[someKey] = $scope.id;
  
    // So that I can emit events like this
    $scope.someEvent = function() {
      $scope.$emit($scope.id + ".someEvent", data);
    }
  }
  </code></pre>
  
  <p>So I think the problem has two parts.</p>
  
  <p>1.) How do I pass someKey from the parent to the child.</p>
  
  <p>2.) How do I set someKey on the parent scope from within the child. Would like to avoid using $parent. Not even sure if this variable is available in the controller?</p>