简体   繁体   English

升级后未在angular 6中定义jQuery

[英]Jquery not defined in angular 6 after upgrade

I recently upgraded my application from Angular-5 to Angular-6 and Jquery suddenly stopped working. 我最近将应用程序from Angular-5 to Angular-6升级from Angular-5 to Angular-6 ,Jquery突然停止工作。 It was working fine in Angular 5 but no longer working in Angular 6. The error states: $(...).DataTable is not a function 它在Angular 5中工作正常,但在Angular 6中不再工作。 The error states: $(...).DataTable is not a function

Make sure you have jQuery added into your angular.json file 确保已将jQuery添加到angular.json文件中

 "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: 顺便说一下,将jQuery与Angular结合使用不是最佳做法,我建议您为插件使用指令:

you can check it out here: Angular Datatables directive 您可以在此处查看: Angular Datatables指令

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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