Show modal with Typescript

Asked

Viewed 633 times

0

Hello, I’m making a code in which I will need to open a modal Bootstrap in Typescript, but I’m not able to do it. Help me there please.

I’ll leave an example for you to pick up here.

function Abrir(){
    document.getElementById("myModal").modal('show');
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<div class="modal fade" id="myModal" role="dialog">
  <div class="modal-dialog modal-sm">
    <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">
        <p>This is a small modal.</p>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-       dismiss="modal">Close</button>
      </div>
    </div>
  </div>
</div>

<button type="" class="btn btn-outline-primary btn-block" onclick="Abrir()">Clique para abrir o modal</button>

I AM NOT USING ANGULAR, MY JOB IS IN . NET

OBS: I need to open with Typescript, I can not use the following way:

<button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Abrir modal</button>

because it won’t open when you click on a button in my project.

  • As far as I know, modal() is not a class method Element. Shouldn’t you be calling this through an object generated by jQuery? With $("#myModal").modal('show')

  • @user140828, I am not using jQuery, it would have to be with Typescript even

  • You have a project written in Typescript, which compiles your end font in javascript?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.