Как использовать jQuery hide boostrap4 Modal с Angular? - PullRequest
0 голосов
/ 26 апреля 2018

Я добавил jquery, начальную загрузку в пакет.JQuery работает нормально, но модальная функция не работает.

ts & html

import $ from 'jquery';
export class AppComponent {
  name = 'Angular 5';

  closeModal() {
    $("#exampleModal").modal('toggle');
  }
}
<!-- Button trigger modal -->
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal">
      Launch demo modal
    </button>

<!-- Modal -->
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
              <span aria-hidden="true">&times;</span>
            </button>
      </div>
      <div class="modal-body">
        ...
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary" (click)="closeModal()">Save changes</button>
      </div>
    </div>
  </div>
</div>

ОШИБКА

TypeError: jquery_1.default(...).modal is not a function

живая демонстрация

https://stackblitz.com/edit/angular-jquery-modal

1 Ответ

0 голосов
/ 26 апреля 2018

Чтобы использовать jQuery в Typescript, вы должны сделать это следующим образом.Строка должна быть размещена после всех импортов.

//import $ from 'jquery';

 declare var $:any;

 export class AppComponent {
   name = 'Angular 5';

   closeModal() {
     $("#exampleModal").modal('toggle');
   }
 }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...