0

I am trying to pass values to a modal over parameters. For some reason this parameter is always undefined when I try to access it in my controller. The second answer of this question is what I am building upon.

Here is my setup for the modal. Please note that $scope.evaluationResult is defined and has valid content.

$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);
}

Here is my controller:

/**
 * 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

    }]);

What is the problem here?

Community
  • 1
  • 1
Stefan Falk
  • 18,764
  • 34
  • 144
  • 286
  • 2
    I not see `'evaluationResult'` inside your inject array - `['$scope', '$modal', '$modalInstance', '$http',`. – Slava Utesinov Mar 23 '16 at 14:11
  • @SlavaUtesinov Yeah, that was it.. I am new to AngularJS .. actually I just have to overtake a project from another colleague. ^^ Thanks :) – Stefan Falk Mar 23 '16 at 14:13

1 Answers1

1

You forgot to put it in injection array, should be:

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

heroandtn3
  • 164
  • 1
  • 7
  • 1
    It should be in single quotes in the injection array, though: `'evaluationResult'`. – Lex Mar 23 '16 at 14:13