2016-03-23 33 views
0

我想通过参数传递值到模态。出于某种原因,当我尝试在控制器中访问它时,此参数始终为undefinedthis question的第二个答案是我正在构建的。为什么这个模态参数总是不确定的?

这是我的模态设置。请注意,$scope.evaluationResult已定义并具有有效内容。

$scope.showEvaluationResult = function() { 
    var modalInstance = $modal.open({ 
     templateUrl: 'evaluation-result/evaluation-result-dlg.html', 
     controller: 'EvaluationResultDialogCtrl', 
     windowClass: 'evaluation-result-dlg', 
     size: 'lg', 
     resolve: { 
      evaluationResult: function() {  
       return $scope.evaluationResult; 
      } 
     } 
    }); 
    setupKeyHandling(modalInstance); 
} 

这里是我的控制器:

/** 
* The controller for displaying evaluation results. 
*/ 
annotatorApp.controller('EvaluationResultDialogCtrl', ['$scope', '$modal', '$modalInstance', '$http', 
    function ($scope, $modal, $modalInstance, $http, evaluationResult) { 
     $scope.trainingLog = { 
      text: '' 
     }; 

     $scope.close = function() { 
      $modalInstance.close(); 
     }; 

     $scope.evaluationResult = evaluationResult; // Always undefined 

    }]); 

有什么问题吗?

+2

我看不到' 'evaluationResult''您的注入阵列内 - '[' $范围 ' '$模式',' $ modalInstance','$ http','。 –

+0

@SlavaUtesinov是的,就是这样..我是AngularJS的新手..其实我只需要从另一个同事那里赶上一个项目。 ^^谢谢:) – displayname

回答

1

你忘了把它注射阵列,应该是:

annotatorApp.controller('EvaluationResultDialogCtrl', ['$scope', '$modal', '$modalInstance', '$http', 'evaluationResult', function ($scope, $modal, $modalInstance, $http, evaluationResult) {

+1

它应该在注入数组中的单引号中,但是:''evaluationResult''。 – Lex

相关问题