Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unknown provider: $uibModalInstanceProvider - Bootstrap UI modal

I have a problem with UI Bootstrap modal.

In one controller I have this:

app.controller("tableCtrl",['$scope','$http','$uibModal','$log' ,function ($scope, $http,$uibModal,$log) {
  $scope.open = function (size,selectedUser) {
  var modalInstance = $uibModal.open({
    animation: $scope.animationsEnabled,
    templateUrl: 'myModalContent.html',
    controller:'ModalInstanceCtrl',
    size: size,
    resolve: {
      user: function () {
        return selectedUser;
      }
    }
  });
}]);

In another I have this:

app.controller('ModalInstanceCtrl',['$scope','$uibModalInstance','user', function ($scope, $uibModalInstance, user) {
  $scope.user = user;
  $scope.ok = function () {
    $uibModalInstance.close();
  };
}]);

myModalContent looks like this:

<script type="text/ng-template" id="myModalContent.html">
    <div class="modal-header"><h1>EDIT</h1></div>
    <div class="modal-body"> 
        {{patient.patient_id}}
    </div>
    <div class="modal-footer">
        <button class="btn btn-primary" type="button" ng-click="ok()">OK</button>
    </div>
</script>

I only call tableCtrl in HTML and call open function like this:

<button class="btn btn-primary" ng-click="open('lg',patient)">Edit</button>

When I click the edit button I receive this exception:

Unknown provider: $uibModalInstanceProvider <- $uibModalInstance

I saw this plunker but it didnt help me.

What is wrong?

like image 964
Marcinek Avatar asked Oct 31 '15 18:10

Marcinek


4 Answers

I had the same problem, so from my solution here's how you could solve your scenario

app.controller("tableCtrl",['$scope','$http','$uibModal','$log' ,function ($scope, $http,$uibModal,$log) {
  $scope.open = function (size,selectedUser) {
  var uibModalInstance = $uibModal.open({
    animation: $scope.animationsEnabled,
    templateUrl: 'myModalContent.html',
    controller:function($uibModalInstance ,$scope,user){
     $scope.ok = function () {
            $uibModalInstance.dismiss('cancel');
         };

    },
    size: size,
    resolve: {
      user: function () {
        return selectedUser;
      }
    }
  });
}]);
like image 96
GeorgeKach Avatar answered Oct 20 '22 05:10

GeorgeKach


The Problem Identified is: My Control was reinitializing from HTML Page. Make sure the Modal controller is initalized from one place

like image 21
Aashish Patil Avatar answered Oct 20 '22 03:10

Aashish Patil


I Had the exact same problem. updating both angular and ui-bootstap library fixed my problem. Use bower to update ui-bootstrap, it suggests the version of angular that is working with it. Hope I helped.

like image 3
Mohamad Ghafourian Avatar answered Oct 20 '22 05:10

Mohamad Ghafourian


I found that this problem occurred when I defined the controller in the template HTML rather than in the modal.open call

like image 3
nuander Avatar answered Oct 20 '22 03:10

nuander