user6656728
user6656728

Reputation:

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?

Upvotes: 2

Views: 6347

Answers (1)

Carol Skelly
Carol Skelly

Reputation: 362320

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

Upvotes: 3

Related Questions