AngularJS范围返回$$ state

时间:2018-07-02 08:50:13

标签: angularjs angularjs-directive angularjs-scope

我有一个指令,在此指令中,我有一个来自控制器的值,这是我的指令:

angular
  .module('thermofluor')
  .directive('tablePlate', tablePlate)


tablePlate.$inject = ['$timeout', '$q'];

function tablePlate($timeout, $q) {
  var directive = {
    link: link,
    restrict: 'E',
    templateUrl: '/crims/thermofluor/experiments/table_plate.html',
    scope: {
      plate: '='
    }
  };

  return directive;

  function link(scope, element) {
    console.log("test");
    var plate = scope.plate;
    console.log(plate);
    scope.letters = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'];
    scope.numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12];

    experiments = [];
    experiments[scope.plate.experiment.well] = [scope.plate.experiment];

    return;
  }
}

问题是,当我console.log作用域时,看到的平板对象具有我需要的所有内容,但是当我尝试console.log scope.plate对象时,对象发生了变化还给我一个$$state,我不知道如何使用此$$state

有人知道吗?

1 个答案:

答案 0 :(得分:1)

//use of the controller with scope will resolve your problem

angular
    .module('thermofluor')
    .directive('tablePlate', tablePlate)


tablePlate.$inject = ['$timeout', '$q'];

function tablePlate($timeout, $q) {
    var directive = {
        link: link,
        restrict: 'E',
        controller: ['$scope',function($scope){
                console.log("test");
                var plate = $scope.plate;
                console.log(plate);
                $scope.letters = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'];
                $scope.numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12];

                experiments = [];
                experiments[$scope.plate.experiment.well] = [$scope.plate.experiment];

        }],
        templateUrl: '/crims/thermofluor/experiments/table_plate.html',
        scope: {
            plate: '='
        }
    };

    return directive;

    function link(scope, element) {
        return;
    }
}