3

I'm trying to open a Bootstrap UI $modal inside a directive. It works, but when I want to add an 'inline' controller (see commented lines in the code below), I get a "[$injector:unpr] Unknown provider: nProvider <- n" error.

Can anyone tell me why?

angular.module('myApp.directives').directive('eModalForm', ['$modal', function ($modal) {

   return {
      restrict: 'A',
      link: function ($scope, $element, $attrs) {

         $scope.openModal = function () {
            console.log('//==//');
            var modalInstance = $modal.open({

                templateUrl: '/App/Templates/modal.html',

                // commented these lines to prevent error:
                //controller: function ($scope, $modalInstance) {
                //  $scope.$modalInstance = $modalInstance;
                //},

                size: 'lg'

            });

         };
      }

   };

}]);

I am calling this function like this:

<div ng-repeat="item in list" ng-click="openModal(item)" e-modal-form>
Sander_P
  • 1,787
  • 1
  • 13
  • 37

1 Answers1

14

The controller dependencies are lost during minification, just use the extended syntax:

controller: ['$scope', '$modalInstance', function ($scope, $modalInstance) {
    ...
}],
...
Nikos Paraskevopoulos
  • 39,514
  • 12
  • 85
  • 90