How to use jQuery with javascript in angular 2

前端 未结 7 813
说谎
说谎 2020-12-05 01:13
    import {Component, ElementRef, OnInit} from \'angular2/core\';
    declare var jQuery:any;
    @Component({
      selector: \'jquery-integration\',
      templat         


        
相关标签:
7条回答
  • 2020-12-05 02:13

    What I do to solve this issue:

    For library doesn't support @types/ and library need to load when document loaded (mean libraries need to add in script tag of document)

    1. Run npm install jquery --save
    2. Add js/css files in scripts or styles of angular-cli.json like

      "scripts": ["../node_modules/path to file", "./assets/path to file"]

    For library supported @types/, just run npm install @types/jquery --save-dev

    To use the library, add declare var jQuery: any; before annotation @Directive or @Component want to use the lib

    P/S: I use angular-cli with webpack in my project, maybe different with systemjs

    0 讨论(0)
提交回复
热议问题