Is there a way to inject $uibModalInstance into uib modal's custom controller using "resolve"?

450 views Asked by At

Suppose I have this code:

$uibModal.open({
  templateUrl: 'some-template.html',
  controller: 'ControllerDefinedElsewhere',
  resolve: {
    // some other resolves here...
    uibModalInstance: ($uibModalInstance) => {
      return $uibModalInstance;
    }
  }
});

As I somehow expected I get the following error:

Error: [$injector:unpr] Unknown provider: $uibModalInstanceProvider <- $uibModalInstance

How can I inject the modal instance in the controller? The most I was able to do was something like:

const modalInstance = $uibModal.open({
  ...
  getModalInstance: () => {
    return () => {
      return modalInstance;
    }

  }
});

//and then in the controller have

$timeout(() => {
  this.modalInstance = getModalInstance();
  // with the mention that I have to pass a function that I would later call since if I just send the value it will be obviously undefined.
}, 30)

however this code smells really bad. is there a cleaner alternative?

0

There are 0 answers