0

私はこのコードを持っています:

.directive('hostelGridBed', function($rootScope){
return {
    restrict: 'E',
    scope: {
      config: '=',
      range: '=',
      days: '='
    },
    link: function(scope, element){

    },
    controller: ['$scope', function($scope){
      $scope.innerStay = '';
      function switchStay(data){
        $rootScope.$broadcast('SwitchStay', {data: data.config});
      };
      $scope.onDropComplete = function(data,evt){
        //$rootScope.$broadcast
        switchStay(data);
        console.log('Drop completo bed!');
      }
    }],
    templateUrl: './js/templates/hostelgridbed.html'
  }
})
.directive('hostelGridDay', function(StaysFactory){
  return {
    restrict: 'E',
    scope: {
      config: '=',
      date: '='
    },
    link: function(scope,element){
    },
    controller: ['$scope','$rootScope', function($scope,$rootScope){
      $scope.switchStay = function(evt, data){
        console.log(data);
        // Here. How can I access this controller's $scope
      }
      $scope.$on('SwitchStay', $scope.switchStay);
    }],
    templateUrl: './js/templates/hostelgridday.html'
  }
})

$broadcast からデータを取得しました。問題ありません。$scope.switchStay 関数内からディレクティブの $scope にアクセスする必要があることを除いて。それを達成する方法はありますか?

4

1 に答える 1