0

假设我有这个代码:

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

正如我以某种方式预期的那样,我收到以下错误:

错误:[$injector:unpr] 未知提供者:$uibModalInstanceProvider <- $uibModalInstance

如何在控制器中注入模态实例?我能做的最多的是:

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)

但是这段代码闻起来很糟糕。有更清洁的选择吗?

4

0 回答 0