EDIT - as the code below is, the modal will work - my issue was I had included ng-app and ng-controller in my HTML template for my modal, however they are not included in the below question.
I've my main controller, modal controller and my modal template HTML
Everything seems to be in order and I cannot for the life of me work out (or find out from stackoverflow) why I keep getting Error: [$injector:unpr] Unknown provider: modalInstanceProvider <- modalInstance <- modalCtrl
error.
BTW $modal
is now depricated, it's $ubiModal
now.
Main ctrl:
var module = angular.module("app", ["agGrid", "ngAnimate", "ngSanitize", "ngDialog", "ui.bootstrap"])
module.controller("mainCtrl", ["$scope", "dataService", "$timeout", "dateFilter", "ngDialog", "$http", "$uibModal", function ($scope, dataService, $timeout, dateFilter, ngDialog, $http, $uibModal) {
$scope.open = function () {
var uibModalInstance= $uibModal.open({
templateUrl: "views/Modal.html",
controller: "modalCtrl",
show: true,
})
};
}]);
my modal controller:
module.controller("modalCtrl", ["$scope", "ngDialog", "dataService", "$uibModalInstance", function ($scope, ngDialog, dataService, $uibModalInstance) {
//do stuff
}]);
and my HTML template:
<div id="loginModal" class="modal show" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" ng-click="closeThisDialog(); printArray()" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h1 class="text-center" style="text-align: center">Entities:</h1>
</div>
<div class="modal-body">
<div>
<div>
<input type="text" placeholder="Search" ng-model="entity">
</div>
</div>
<div ng-repeat="entity in entityArray | filter:entity">
<label>
<input style="float: left; margin-top: 5px" type="checkbox" ng-model="entityChecked" ng-change="getEntityFromModal(entity, entityChecked)" />
<span>{{entity}}</span>
</label>
</div>
</div>
<button ng-click="okButtonEntity();" >OK</button>
</div>
</div>
</div>
This kind of error occurs when you write in a dependency for a controller, service, etc, and you haven't created or included that dependency. In this case, $modal isn't a known service.
The $modal service has been renamed to $uibModal. // create the module, pass in modules it depends on var app = angular.module ('myApp', ['ui.bootstrap']); // $modal service is now available via the ui.bootstrap module we passed in to our module app.controller ('myCtrl', function ($scope, $uibModal) { //code here });
It sounds like you didn't pass in ui-bootstrap as a dependency when bootstrapping angular. angular.module ('myModule', ['ui.bootstrap']); Also, be sure you are using the latest version of ui-bootstrap (0.6.0), just to be safe. The error is thrown in version 0.5.0, but updating to 0.6.0 does make the $modal service available.
The obvious answer for the provider error is the missing dependency when declaring a module as in the case of adding ui-bootstrap. The one thing many of us do not account for is the breaking changes when upgrading to a new release.
$modalInstance
has since been changed (deprecated) to $uibModalInstance
with the latest ui bootstrap (0.14.3). Also it should be $modalInstance
with older versions.
i.e
module.controller("modalCtrl", ["$scope", "ngDialog", "dataService", "$uibModalInstance",
function ($scope, ngDialog, dataService, $uibModalInstance) {
Documentation
controller - a controller for a modal instance - it can initialize scope used by modal. Accepts the "controller-as" syntax in the form 'SomeCtrl as myctrl'; can be injected with $uibModalInstance
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