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