您可能希望在全球范围内设置一个服务来为您执行此操作,您可以将所需的任何内容传递给模态以使其工作,就像这样 -
.service(metadata.componentName, [
'$modal',
'$q',
function($modal, $q) {
return {
confirm: function confirmModal(options) {
return $q(function(resolve, reject) {
$modal.open({
size: 'sm',
template: '<div class="modal-body">' + options.message + '</div><div class="modal-footer"><button class="btn btn-primary" ng-click="ok()">OK</button><button class="btn btn-warning" ng-click="cancel()">Cancel</button></div>',
controller: modalCtrlRJS.componentName
}).result.then(resolve, reject);
});
},
info: function infomModal(options) {
return $q(function(resolve, reject) {
$modal.open({
size: 'sm',
template: '<div class="modal-body"> <button type="button" class="close" ng-click="ok()"><span>×</span></button>' + options.message + '</div>',
controller: timeoutModalCtrlRJS.componentName
}).result.then(resolve, reject);
});
},
error: function errormModal(options) {
return $q(function(resolve, reject) {
$modal.open({
size: 'sm',
template: '<div class="modal-body"> <button type="button" class="close" ng-click="ok()"><span>×</span></button>' + options.message + '</div>',
controller: timeoutModalCtrlRJS.componentName
}).result.then(resolve, reject);
});
}
};
}
所以这些都是简单的模态,这里的技巧是你可能会使用templateUrl 而不是模板,并传入你自己的控制器。我在这里使用 requirejs 语法传递控制器。像这样的东西应该可以为您解决问题,然后您只需致电yourService.whateverModal 并传递您需要的任何参数。您也可以在该服务调用中在 bootstrap-ui 模式上传递您需要的任何额外设置,这取决于您需要自定义多少。
只有 1 条附加评论 - 我已将它们包装在 $q 中,因此您可以在调用此模式服务时选择使用承诺。例如 - 当模型关闭或取消时,我使用它来触发不同的事件。