0

I have an application with add and edit modal,when click edit or add ;it's open a modal. my Problem is :I want to have a function that's open a modal Just by call it and this function I want to define it in the root scope,when I do that I have an error in the resolve function.

DefaultModule.controller("navCtrl", function ($scope, $rootScope, $uibModal) {       
    $rootScope.OpenModal = function (templateModalUrl, controllerModal, resolveFun) {
        $uibModal.open({
            animation: true,
            templateUrl: templateModalUrl,
            controller: controllerModal,
            resolve: {
                resolveFun
            }
        }).result.catch(function (res) {
            if (!(res === 'cancel' || res === 'escape key press')) {
                //throw res;
            }
        });
    }
});

calling it:

$scope.editBusiness = function (business) {
    var ObjResolve = function () {
        return business;
    }
    $rootScope.OpenModal("BusinessTypesModal.html", "ModalInstanceCtrl", ObjResolve);
};

and the error that's I get:

Error: $injector:unpr Unknown Provider Unknown provider: ObjResolveProvider <- ObjResolve <- ModalInstanceCtrl

P.S. the template of the modal is defined in another controller -not navCtrl Controller-

georgeawg
  • 48,608
  • 13
  • 72
  • 95
Rawan Mansour
  • 111
  • 2
  • 16
  • 1
    Are you sure that the file that contains `ModalInstanceCtrl` is actually loaded, e.g. in your index.html or however you include your files? The error hints on `ModalInstanceCtrl` never being declared which usually means that the file is not included during page load. As a side note, I suggest putting the function `OpenModal` into a service and injecting the service whenever it's needed. That`s a cleaner option than putting it in `$rootScope`. – Florian Lim Feb 10 '19 at 23:26
  • @FlorianLim yes thank you that's a pretty Answer – Rawan Mansour Feb 11 '19 at 07:23
  • but I still have the same error – Rawan Mansour Feb 11 '19 at 08:13
  • 1
    After checking the error message again, I see that the problem is not the `ModalInstanceCtrl` but the `ObjResolve` parameter. That has to meet certain criteria, as can be seen in another SO question: [Angular uibModal, Resolve, Unknown Provider](https://stackoverflow.com/a/35352546/634872). The relevant part is _Your resolve object needs to be a map of string: function_. – Florian Lim Feb 11 '19 at 11:56

0 Answers0