I have a common confirmation modal service, already created and used in another modal - Create User. In Create User controller, I call the below onModalCancel to close the Create User modal when user clicks on Cancel of the confirmation modal
vm.onModalCancel = function onModalCancel() {
return ConfirmationModalService.openModal({
modalTitle: vm.resourceIdFor.cancelThisUpload
})
.then(function (modalResponse) {
if (modalResponse.isConfirmed()) {
$modalInstance.dismiss('cancel');
return;
}
return;
});
};
Now I am trying to open the modal from the stateprovider route when user uses the /new-user url, as below
(function () {
'use strict';
angular
.module('mo.pages.new-user.layouts', ['ui.router', 'ui.bootstrap'])
.config(['$stateProvider', newUserRouteConfiguration]);
function newUserRouteConfiguration($stateProvider, $modalInstance) {
$stateProvider
.state('new-user', {
url: '/new-user/{objectType:int}/{objectId:int}',
templateUrl: 'modules/pages/shared/modals/new-user/new-user-modal.html',
controller: 'mo.pages.shared.modals.NewUserModalController as vm',
windowClass: 'new-user-modal',
resolve: {
headerText: function () {
return 'header';
}
}
});
}})();
The issue, i am facing is that, I get the error - Unknown provider: $modalInstanceProvider <- $modalInstance <- mo.pages.shared.modals.NewUserModalController. I know there is the dependency of $modalInstance in the NewUserModalController and i tried to resolve that by passing a $modalInstance, but still getting this error! The NewUserModalController defination is as below :
(function () {
'use strict';
angular
.module('mo.pages.shared.modals')
.controller('mo.pages.shared.modals.NewUserModalController', NewUserModalController);
NewUserModalController.$inject = [
'headerText', '$window', '$q', '$modalInstance', 'mo.common.ConfirmationModalService'
];
function NewUserModalController(headerText, $window, $q, $modalInstance, ConfirmationModalService) {
/* Logic */
}})();
The modal opens without an issue, if I try to open the modal from the controller directly using the $modal.open and passing the template. It is giving the issue when I try to open the modal using the stateprovider
NewUserModalController
You may have forgotten the $modalInstance provider – Ron Brogan