Pass variables to a dynamic Controller inside a Directive AngularJS

I got a directive that loads a different template depending on the variable type that is passed to it. I pass to the isolated scope of the directive the variables patient and service too.

.directive('serviceCharts', serviceCharts);

function serviceCharts() {
  return {
    restrict: 'E',
    link: function (scope, element, attrs) {
      if(attrs.type) {
         scope.template = 'views/' + type + '.html';
    attrs.$observe('type', function (type) {
      if(attrs.type) {
        scope.template = 'views/' + type + '.html';
  template: '
', scope:{ patient:'=', service:'=' } };


In the template (views/myservice.html for example) I load the controller:


And in the controller (myCtrl) I access to the patient and service this way:

  service = $scope.$parent.$parent.service;
  patient = $scope.$parent.$parent.patient;

This works fine, but I don’t like this way of accessing the variables via the $parent.$parent. This is messing with my tests too.

Is there another (better) way to do this?

Thank you!

Source: stackoverflow-javascript