我有一个简单的案例,我将模态定义为组件并使用 uiModal.open 打开该模态。但是,当我想使用 open 方法上的“resolve”和控制器构造函数上的参数将任何自定义数据传递给该模式时,数据不会传递。还尝试注入 $uibModalInstance 失败并出现错误 Unknown provider: $uibModalInstanceProvider <- $uibModalInstance 所以我在关闭模式时无法返回结果。
模板:
<div class="modal-header">
<h3 class="modal-title" id="modal-title">Modal</h3>
</div>
<div class="modal-body" id="modal-body">
Some text
<div class="row">
<div class="col-sm-10">
<textarea class="form-control" name="closureNotes" rows="6" data-ng-model="vm.closureNote" required>
</textarea>
</div>
</div>
</div>
<div class="modal-footer">
<button class="btn btn-default btn-close" type="submit" ng-click="vm.ok()">Close Exception Request</button>
<button class="btn btn-danger" type="button" ng-click="vm.cancel()">Cancel</button>
</div>
零件:
import template from './closeExceptionModal.html';
import controller from './closeExceptionModal.controller';
let closeExceptionModalComponent = {
restrict: 'E',
bindings: {
resolve: '<',
close: '&',
dismiss: '&'
},
template,
controller,
controllerAs: 'vm'
};
export default closeExceptionModalComponent;
控制器:
class CloseExceptionModalController {
constructor() {
//I need to retrieve here some data from caller
}
ok() {
this.close(); //I need to pass here result to caller using modalInstance.close
}
cancel() {
this.dismiss();
}
}
export default CloseExceptionModalController;
调用者控制器代码:
//I need to pass some data to modal
let modalInstance = this.$uibModal.open({
animation: true,
component: 'closeExceptionModal',
appendTo: angular.element(document.body),
})
modalInstance.result.then( (result) => {
alert(result); //this must be result data from modal
}, () => {
});