javascript - 如何从 angularjs 中的 Controller 调用 Ui-Bootstrap 0.10.0 中的 $modal.open

标签 javascript angularjs angular-ui angular-ui-bootstrap

如何在 Angular js 中从 Controller 调用 $modal.open。以前在 ui-bootstrap 0.1.0 对话框中有。现在在当前版本中调用对话框的权限是什么。

在 0.1.0 中它只是 $dialog.dialog();然后调用Dialog();在图书馆 -

return {
  // Creates a new `Dialog` with the specified options.
   dialog: function(opts){
      return new Dialog(opts);
},

// creates a new `Dialog` tied to the default message box template and controller.
//
// Arguments `title` and `message` are rendered in the modal header and body sections respectively.
// The `buttons` array holds an object with the following members for each button to include in the

// modal footer section:

// * `result`: the result to pass to the `close` method of the dialog when the button is clicked

// * `label`: the label of the button
// * `cssClass`: additional css class(es) to apply to the button for styling

messageBox: function(title, message, buttons){
    return new Dialog({templateUrl: 'template/dialog/message.html', 
           controller: 'MessageBoxController', resolve: {model: {
      title: title,
      message: message,
      buttons: buttons
    }}});
}

有谁知道如何在 0.10.0 中调用 $modal.open 吗?

最佳答案

设置函数打开:(设置模板、 Controller 、解析)

function open() {

var modalInstance = $modal.open({
  templateUrl: 'myModalContent.html',
  controller: ModalInstanceCtrl,
  resolve: {
    items: function () {
      return $scope.items;
    }
  }
});

});

设置模态 Controller :

var ModalInstanceCtrl = function ($scope, $modalInstance, items) {

    $scope.items = items; 

});

并在需要时调用它:

open();

如果你想从模板调用:

替换

function open() {

$scope.open = function() {  

并调用

$scope.open()

关于javascript - 如何从 angularjs 中的 Controller 调用 Ui-Bootstrap 0.10.0 中的 $modal.open,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21751729/

相关文章:

javascript - 无法在 HTML 中设置 <select> 的 ng-model

angularjs - Angular ui-sortable + angular-gridster

javascript - 无法加载资源 : the server responded with a status of 404 (Not Found) Unable to resolve this issue

javascript - 如何删除所有 jQuery 事件(或者只是不重新初始化两次)

javascript - Angular $scope 将 push() 视为未定义

android - 错误 : Source path does not exist: resources\android\icon\drawable-hdpi-icon. png

javascript - 使用 Angular 格式化文本输入

javascript - Angular Bootstrap Accordion 未正确折叠

javascript - 使用 chrome.history.deleteRange 未完全删除历史记录

javascript - iphone 浏览器上的以下代码有什么问题?