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?
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;
}
}
});
}]);
The Problem Identified is: My Control was reinitializing from HTML Page. Make sure the Modal controller is initalized from one place
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.
I found that this problem occurred when I defined the controller in the template HTML rather than in the modal.open call
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With