简体   繁体   中英

Launch bootstrap modal on page load AngularJS

I am creating a web app with AngularJS,

I want to launch a bootstrap modal on page load from AngularJS,

Here is my modal:

<div class="modal hide fade" id="myModal">
    <div class="modal-header">
        <a class="close" data-dismiss="modal">×</a>
        <h3>Modal header</h3>
    </div>
    <div class="modal-body">
        <p>One fine body…</p>
    </div>
    <div class="modal-footer">
        <a href="#" class="btn">Close</a>
        <a href="#" class="btn btn-primary">Save changes</a>
    </div>
</div>

and here is my controller

<script>
    var app = angular.module('myapp', []);
    app.controller('myctrl', function ($scope, $window, $http) {
        $('#myModal').modal('show');
    })
</script>

What is a correct way of launching modal on page load?

It's because the modal structure is wrong, and the hide class is preventing it from showing.

  <div class="modal fade" id="myModal">
      <div class="modal-dialog" role="document">
          <div class="modal-content">
          ..
          </div>
          <!-- /.modal-content -->
      </div>
  </div>

Demo on Codeply

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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