title: Getting controller name from $parent in AngularJS
body: <p>I have converted one of my Angular controllers to Controller As syntax, but I am having trouble getting an ng-grid template to play nicely.</p>
  
  <p>The controller has a function called edit user that looks like this</p>
  
  <pre><code>self.editUser = function (user_data) {
      var modalInstance = $modal.open({
          templateUrl: '/admin/views/adminuser.html',
              controller: 'AdminUserController',
              resolve: {
                  user_data: function () {
                      return user_data;
                  }
              }
          });
  
          modalInstance.result.then(function () {
              self.myQueryData.refresh = !self.myQueryData.refresh;
          });
      };
  </code></pre>
  
  <p>the ng-grid template looks like this</p>
  
  <pre><code>&lt;div class="ngCellText" ng-class="col.colIndex()"&gt;
      &lt;a ng-click="$parent.$parent.$parent.$parent.editUser({user_id:row.entity.id, first_name:row.entity.first_name, last_name:row.entity.last_name, email:row.entity.email})"&gt;
          &lt;span ng-cell-text translate&gt;Edit&lt;/span&gt;
      &lt;/a&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>and my route looks like this</p>
  
  <pre><code>.when('/admin/settings', {
      templateUrl: '/admin/views/settings.html',
      controller: 'SettingsController as sc',
  })
  </code></pre>
  
  <p>So the problem is in the template when I call</p>
  
  <pre><code>$parent.$parent.$parent.$parent.editUser 
  </code></pre>
  
  <p>it doesn't know what I am talking about unless I include the controller name like </p>
  
  <pre><code>$parent.$parent.$parent.$parent.sc.editUser, 
  </code></pre>
  
  <p>then it works great. However I don't want to bind this template directly to the sc controller. How can I call the editUser without using the controller name?</p>
  
  <p>I was hoping there would be a function on the $parent that would supply the function name like </p>
  
  <pre><code>$parent.$parent.$parent.$parent.getController().editUser
  </code></pre>
  
  <p>Any suggestions?</p>