$ не определен при попытке реализовать jquery в anular - PullRequest
0 голосов
/ 23 февраля 2020

Я пытаюсь реализовать функцию jquery на angular, при которой модал появляется после таймаута, но на моей консоли появляется следующая ошибка:

$ не определено

Я установил jquery из npm, а также экспортировал его в мой тег angular. json scripts как:

scripts": [
              "node_modules/jquery/dist/jquery.min.js",
              "node_modules/popper.js/dist/popper.min.js",
              "node_modules/bootstrap/dist/js/bootstrap.min.js"
            ]

файл component.ts:

import { Component, OnInit } from '@angular/core';
declare var $; 
@Component({
  selector: 'app-home',
  templateUrl: './home.component.html',
  styleUrls: ['./home.component.scss']
})
export class HomeComponent implements OnInit {
  constructor() { }
  ngOnInit() {
  $(window).load(function(){
    setTimeout(function(){
        $('#myModal').modal('show');
    }, 2000);
 });
  }
}

HTML:

<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-dialog-scrollable" role="document">
      <div class="modal-content">
        <div class="modal-header">
          <h5 class="modal-title" id="myModalLabel">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">Save changes</button>
        </div>
      </div>
    </div>
  </div>

1 Ответ

0 голосов
/ 23 февраля 2020

Вам необходимо объявить символ jQuery, например, в вашем app.component add:

declare var $: any;
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...