我想用 Async API 构建一个模态指令来打开模态。我在想的是一个工厂,它返回给我操作模态指令的 API 对象。使用 Angular-UI Bootstrap 0.6.0 我想要这样的东西:
Module.factory("ModalAPI", function ($modal)
var ModalAPI;
ModalAPI.confirm = function (title, text, buttons) {
// Set up a confirmation modal
return $modal.open(options).result;
};
return ModalAPI;
});
到目前为止,一切都很好。现在要设置模态,我想:
Module.factory("ModalAPI", function ($modal)
var ModalAPI,
Modal;
Modal = {};
ModalAPI.contents = function () {
return Modal;
}
ModalAPI.confirm = function (title, text, buttons) {
Modal.title = title;
Modal.text = text;
Modal.buttons = processButtons(buttons);
return $modal.open(options).result;
};
return ModalAPI;
});
Module.directive("modal", function(ModalAPI) {
return {
restrict: "A",
link: function (scope, elem, attrs) {
scope.modal = ModalAPI.contents();
},
template: "<div class='modal-header'>" +
" <h2>modal.title</h2>" +
"</div>" +
"<div class='modal-body'>" +
" <h2>modal.text</h2>" +
"</div>" +
"<div class='modal-footer'>" +
" <button ng-click='$close(button.result)' ng-repeat='button in buttons'>{{button.label}}</button>" +
"</div>"
};
});
问题是如何设置Modal
仅与指令共享对象而不与其他人共享对象的模式?