有没有办法使用"解决"?将uibModalInstance注入uib模式的自定义控制器?

时间:2017-06-22 13:22:50

标签: angularjs angular-ui-bootstrap angular-ui-modal

假设我有这段代码:

$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)
然而,这段代码闻起来很糟糕。有更清洁的选择吗?

0 个答案:

没有答案
相关问题