How can I use jQuery in an Angular 8 app?

后端 未结 3 1427
南方客
南方客 2020-12-16 03:05

I have an application that utilizes SignalR to communicate with a desktop application. To utilize SignalR I need to use jQuery in my .ts file. However, it doesn\'t seem to w

3条回答
  •  攒了一身酷
    2020-12-16 03:29

    Angular 8 works with JQuery.

     "dependencies": {
      ...
      "jquery": "^3.4.1",
      ...
    }
    

    in your angular.json file import the required file like this:

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

    no ./ at the beginning, just node_modules/...

    In your app.module verify it is working like this:

    import { AppComponent } from './app.component';
    
    declare var $: any;
    console.log(`jQuery version: ${$.fn.jquery}`);
    
    @NgModule({
    

    In the developer tools console it should print this:

    jQuery version: 3.4.1

提交回复
热议问题