Angularjs 将隔离范围变量从指令传递到其控制器

Angularjs 将隔离范围变量从指令传递到其控制器,angularjs,angularjs-directive,angularjs-scope,Angularjs,Angularjs Directive,Angularjs Scope,我创建了一个使用隔离作用域的指令。我正在从视图中传递一个变量 指令 function abcDirective() { return { restrict: 'AEC', templateUrl: 'abc.html', controller: 'ABController as abCtrl', scope: { dataSent: '=' } } } 视图 <div

我创建了一个使用隔离作用域的指令。我正在从视图中传递一个变量

指令

function abcDirective() {
    return {
        restrict: 'AEC',
        templateUrl: 'abc.html',
        controller: 'ABController as abCtrl',
        scope: {
            dataSent: '='
        }
    }
}
视图

<div abc-directive data-sent="{some: Object}"></div>

现在,当我打开Batarang时,我看到一个ABCtrl对象和所有范围元素。一个对象具有
{some:object}
。我希望这个
{some:object}
成为ABCtrl的一部分。我该怎么做

谢谢。

有一个允许您通过指令定义上的
bindToController
属性来指定此项

{
  scope: {
     dataSent:'='
  },
  bindToController:true
}
在此之前,您必须在链接功能或指令控制器内手动执行:

{
   //Using the link function
   link:function(scope, elem, attrs, ctrl){
      ctrl.dataSent = scope.dataSent;

      scope.$watch('dataSent', function(){
         ctrl.dataSent = scope.dataSent;
      });
   }
}

//Using the controller
var ABCController = function($scope){
   this.dataSent = $scope.dataSent;

   $scope.$watch('dataSent', function(){
      this.dataSent = $scope.dataSent;
   }.bind(this));
}

我不确定我是否完全理解。你能在js小提琴或包括你的控制器代码plz