displayname displayname - 4 months ago 9
AngularJS Question

Why is this parameter for modal is always undefined?

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?

Answer

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

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