2

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?

3
  • Have you tried your code ? Have you an error ? Commented Mar 14, 2017 at 8:23
  • no but my page is been fade out a bit @Weedoze Commented Mar 14, 2017 at 8:24
  • you should use angular-ui-bootstrap for a good solution Commented Mar 14, 2017 at 9:07

1 Answer 1

3

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.