为什么模态的这个参数总是未定义的?

时间:2016-03-23 14:04:40

标签: angularjs

我正在尝试将值传递给参数的模态。出于某种原因,当我尝试在控制器中访问它时,此参数始终为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

    }]);

这里有什么问题?

1 个答案:

答案 0 :(得分:1)

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

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