Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

$uibModalInstance undefined (AngularJS UI.Bootstrap)

Why is $uibModalInstance unable to be injected here?

http://plnkr.co/edit/mi9Ytv0HaqE47ENod4Gn?p=preview

baseController.$inject = ['$uibModal', '$uibModalInstance'];

function baseController($uibModal, $uibModalInstance) {

self.ok = function () {
$uibModalInstance.close(self.selected.item);
};

self.cancel = function () {
$uibModalInstance.dismiss('cancel');
};

I am trying to access $uibModalInstance and if I try to inject it, I get an injection error.

If I don't inject it, then it's Undefined...

like image 296
RenleyRenfield Avatar asked Nov 17 '15 19:11

RenleyRenfield


1 Answers

So LOTS of great statements here, but none of them quite solved the issue.

amg-argh got my plkr working with the way I had set up my injection

http://plnkr.co/edit/GXXmUosUEnEO3Tk0gUyp?p=preview

The biggest magic came from this edit here...

var childController = function ($scope, $uibModalInstance) {
        $scope.ok = function () {
            $uibModalInstance.close({ my: 'data' });
        }
        $scope.cancel = function () {                
            $uibModalInstance.dismiss();
        }
    }

    self.open = function (size) {

        var modalInstance = $uibModal.open({
            animation: self.animationsEnabled,
            templateUrl: 'help.html',
            controller: childController,
            size: size
        });
    };

+++++++++++++++++++++++++++++

I also want to make a note that this SHOULD be done later on as a Service, just as icfantv has pointed out. But I need to figure out the syntax for returning and consuming the modal's promise...

Thank you everyone for your help!!

Cheers!

like image 176
RenleyRenfield Avatar answered Nov 11 '22 05:11

RenleyRenfield