Angular bootstrap modal causes a severe error, not sure why

A strange problem using Angular UT bootstrap modal I have no problem at all with Angular 1.3 beta 16, however if I turn on ng-strict-di mode, I get the following error:

Error: [$injector:strictdi] function($scope, $modalInstance) is not using explicit annotation and cannot be invoked in strict mode
http://errors.angularjs.org/1.3.0-beta.16/$injector/strictdi?p0=function(%24scope%2C%20xmodalInstance)
    at http://localhost:3000/vendor/angular.js:78:12
    at annotate (http://localhost:3000/vendor/angular.js:3353:17)
    at invoke (http://localhost:3000/vendor/angular.js:4037:21)
    at Object.instantiate (http://localhost:3000/vendor/angular.js:4070:23)
    at http://localhost:3000/vendor/angular.js:7451:28
    at http://localhost:3000/vendor/ui-bootstrap-tpls-0.11.0.min.js:8:28715
    at wrappedCallback (http://localhost:3000/vendor/angular.js:11616:81)
    at http://localhost:3000/vendor/angular.js:11702:26
    at Scope.$eval (http://localhost:3000/vendor/angular.js:12797:28)
    at Scope.$digest (http://localhost:3000/vendor/angular.js:12609:31) 

The strange thing is that this is not in a directive or service, it is only a script behind one of my pages. I know that I am doing the controller there, but ... well, I'm not sure about that. Here is the code that generated the error:

            //=================
            //MODAL PROMPTER
            //=================

            var Prompt = function(title, prompt) {
                var modalInstance = $modal.open({
                    template: '<div class="modal-header"><h3 class="modal-title">' + title + '</h3></div><div class="modal-body"><p>' + prompt + '</p></div><div class="modal-footer"><button class="btn btn-primary" ng-click="ok()">OK</button><button class="btn btn-warning" ng-click="cancel()">Cancel</button></div>',
                    controller: ModalInstanceCtrl,
                    size: 'sm'

                });

                modalInstance.result.then(function(result) {
                    console.log('Modal OK');
                }, function() {
                    console.log('Modal dismissed');
                });
            };

            var ModalInstanceCtrl = function($scope, $modalInstance) {
                $scope.ok = function() {
                    $modalInstance.close(true);
                };
                $scope.cancel = function() {
                    $modalInstance.dismiss(false);
                };
            };

            //end of modal
            //==================

            //call it immediately to see the error     
            Prompt('myTitle', 'myMessage');

I am not sure how and why I get the error. If I turn off strict-di, it works fine. Any ideas?

+4
source share
2 answers

, ng-strict-di enabled.

function ModalInstanceCtrl ($scope, $modalInstance) { //or var ModalInstanceCtrl = function(...

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

  $scope.cancel = function () {
    $modalInstance.dismiss(false);
  };

};

ModalInstanceCtrl.$inject = ['$scope', '$modalInstance'];
+9

, .

, :

controller: ['$scope', '$modalInstance', ModalInstanceCtrl]
0

All Articles