从控制器触发模态弹出窗口

MrP*_*ram 2 twitter-bootstrap angularjs angular-ui-bootstrap bootstrap-modal

我有一个bootstrap模式弹出窗口,我用我的modalcontroller填充数据.在我填写数据后,我想展示它.为了能够在进入页面时立即显示modalpopup,我想直接触发它.现在我有一个按钮可以做到这一点,但我怎么能以适当的方式自动完成呢?

<!-- Trigger the modal with a button -->
<button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Open Modal</button>

<!-- Modal -->
<div id="myModal" class="modal fade" role="dialog" ng-init="getAllItems()">
    <div class="modal-dialog">

        <!-- Modal content-->
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">&times;</button>
                <h4 class="modal-title">Modal Header</h4>
            </div>
            <div class="modal-body">
                <div class="">
                    <form class="form-horizontal" name="form" role="form">
                        <div ng-repeat="item in items">
                            <input type="radio" name="fundselector" ng-model="item" ng-value="item"/> {{item}} <br />
                        </div>
                    </form>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
            </div>
        </div>

    </div>
</div>
Run Code Online (Sandbox Code Playgroud)

我的控制器:

angular.module("Modal")
.controller("ModalController",
[
"$scope", "$rootScope", "$location", "ModalService", "AuthenticationService",
function ($scope, $rootScope, $location, ModalService, AuthenticationService) {

    AuthenticationService.GetCurrentWindowsUser(function(username) {
        $scope.username = username;
    });

    $scope.getAllItems = function () {
        AuthenticationService.GetCurrentWindowsUser(function (username) {
            if (username) {
                AuthenticationService.GetItems(username, function (items) {
                    $scope.items = items;
                    //Trigger modalpopup here
                });
            }
        });
    }
}
]);
Run Code Online (Sandbox Code Playgroud)

mgi*_*esa 5

不要使用jquery,使用angular-ui.

https://angular-ui.github.io/bootstrap/#/modal

您可以像下面一样以编程方式打开模式,并在解析中传递您的数据.这是从他们的例子直接复制和粘贴.

var modalInstance = $uibModal.open({
      animation: $scope.animationsEnabled,
      templateUrl: 'myModalContent.html',
      controller: 'ModalInstanceCtrl',
      size: size,
      resolve: {
        items: function () {
          return $scope.items;
        }
      }
    });
Run Code Online (Sandbox Code Playgroud)