简体   繁体   English

将jquery + Bootstrap模态对话框div更改为BootStrap + angularjs

[英]Change jquery + Bootstrap modal-dialog div to BootStrap + angularjs

I have multiple bootstrap dialog divs in one single jsp. 我在一个jsp中有多个引导对话框div。

Dialog divs look like below 对话框div如下所示

<div id="manage-notes-dialog" class="modal fade" role="dialog">
<div class="modal-dialog">
    <div class="modal-content">
        <div class="modal-header">
            <h3 id="about">NOTES <input name="backButton" type="button" value="&#8666; " class="btn btn-primary pull-right" /></h3>
        </div>
        <div class="modal-body">
            .......UI HTML.........
            .......UI HTML.........
        </div>
        <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        </div>
    </div>
</div>
</div>

In my jquery button clicks I was opening the dialogs as below 在我的jquery按钮单击中,我打开如下对话框

$("#manage-notes-dialog").modal('show');

Above command being part of jquery click action for button 上面的命令是jQuery的单击按钮的动作

I am changing my UI handling from jQuery to angularjs. 我正在将UI处理从jQuery更改为angularjs。

After writing the angularjs controller and testing it I wrote below code to open the above dialogs. 在编写了angularjs控制器并对其进行测试之后,我编写了以下代码以打开上述对话框。

$scope.openNotes = function() {
    $("#manage-notes-dialog").modal('show');
};

This still not completely using angularjs as $("#manage-notes-dialog").modal('show'); 这仍然没有完全将angularjs用作$("#manage-notes-dialog").modal('show'); is still jQuery and stops when I remove the jquery js. 仍然是jQuery,并在删除jquery js时停止。

I wanted to know if I can have the bootstrap modal dialogs opened through angularjs. 我想知道是否可以通过angularjs打开引导模式对话框。 I want to avoid to re-write all modal dialog from scratch while using angularjs as a lot of data is being loaded via JSTL. 我想避免在使用angularjs时从头开始重新编写所有模式对话框,因为很多数据是通过JSTL加载的。 I am pretty new to angularjs And doing what has been said in this “Thinking in AngularJS” if I have a jQuery background? 我对angularjs很陌生如果我有jQuery背景,那么按照“在AngularJS中思考”中所说的做些什么 not that simple 没那么简单

Please suggest possible workaround/solution steps. 请提出可能的解决方法/解决方案步骤。 Most of the solution/examples I have found are completely using angularjs modal directive. 我发现的大多数解决方案/示例都完全使用angularjs modal指令。 or individual html. 或单个html。

My constraint is that I want to keep all the dialogs in one single jsp as they would be common to multiple UI pages 我的约束是我想将所有对话框保存在一个单独的jsp中,因为它们对于多个UI页面是通用的

I went by what Matthew Green suggested in his comment . 我接受了马修·格林(Matthew Green)在评论中的建议。 Using ng-template I generated div and loaded it via angularjs uibModal open call. 使用ng-template我生成了div并通过angularjs uibModal打开调用加载了它。 Wrote a separate controller dialogController which will handle all actions and scope variable and actions used by my Modal div. 编写了一个单独的控制器dialogController,它将处理我的Modal div使用的所有动作和范围变量以及动作。

Below is the javascript call I used to open the div from the template cache. 以下是我用来从模板缓存中打开div的javascript调用。

var modalInstance = $uibModal.open({
                              templateUrl: 'error-dialog',
                              controller: 'dialogController',
                              scope: $scope,
                              resolve: {                   
                                  msg: function(){
                                  return 'ErrorMessage for DIsplay';
                                }
                            }
                    });

The div element inside the javascript looks below javascript中的div元素如下所示

<script type="text/ng-template" id="error-dialog">
            <div class="modal-body alert-danger">
                <button type="button" class="btn btn-default pull-right" data-dismiss="modal" ng-click="close()">&#10539;</button>
                <pre class="alert-danger" style="border:0px;">{{msg}}</pre>
            </div>
</script>

And finally the controller 最后是控制器

.controller('dialogController', [ '$scope','msg','$uibModalInstance' ,function($scope, msg,$uibModalInstance) {
    $scope.msg = msg;
    $scope.close = function() {
         $uibModalInstance.dismiss('cancel');
        };
} ])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM