简体   繁体   中英

Jquery not defined in angular 6 after upgrade

I recently upgraded my application from Angular-5 to Angular-6 and Jquery suddenly stopped working. It was working fine in Angular 5 but no longer working in Angular 6. The error states: $(...).DataTable is not a function

Make sure you have jQuery added into your angular.json file

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

And make sure to add the following to your component

declare var jquery:any;
declare var $ :any;

Outside the export class.

By the way it's not the best practice to use jQuery with Angular, I recommend you using a directive for the plugin instead:

you can check it out here: Angular Datatables directive

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM