我有一个指令,在此指令中,我有一个来自控制器的值,这是我的指令:
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
有人知道吗?
答案 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;
}
}