如何在Angular 7中使用jQuery插件

如何在Angular 7中使用jQuery插件,jquery,angular,typescript,jquery-plugins,angular7,Jquery,Angular,Typescript,Jquery Plugins,Angular7,我正在使用一个js插件来扩展jQuery以转换xml2json。() 我在我的遗留AngularJs应用程序中使用了它,它工作正常,但现在我已经升级到Angular7了,我不知道如何设置它 我在angular.json文件中包括了jQuery和插件,如下所示: script: [ "node_modules/jquery/dist/jquery.slim.js", "src/app/plugins/jquery.xml2json.js" //N

我正在使用一个js插件来扩展jQuery以转换xml2json。()

我在我的遗留AngularJs应用程序中使用了它,它工作正常,但现在我已经升级到Angular7了,我不知道如何设置它

我在
angular.json
文件中包括了jQuery和插件,如下所示:

script: [
  "node_modules/jquery/dist/jquery.slim.js", 
  "src/app/plugins/jquery.xml2json.js"  //Note: I've edited the position of the scripts
]
然后我就这样使用它:

script: [
  "node_modules/jquery/dist/jquery.slim.js", 
  "src/app/plugins/jquery.xml2json.js"  //Note: I've edited the position of the scripts
]
//app.component.ts
从“jquery”导入*为$
导出类AppComponent{
myFunction(){
让xmlDocument=“test”;
$.xml2json(xmlDocument);
}
}
但是我得到了这个错误

_plugins_jquery_xml2json_js__WEBPACK_IMPORTED_MODULE_3__.xml2json is not a function

有什么建议吗?

据我所知,在angular.json文件中引用JavaScript文件时,angular编译器将按照脚本数组中的顺序将它们插入到一个文件中。 在您提供的示例中,它将首先编写
src/app/plugins/jquery.xml2json.js
内容,然后再编写
node\u modules/jquery/dist/jquery.slim.js
内容

请尝试交换项目的位置,让我知道这是否有效

请注意,我发现了这个NPM包,您可以使用它将xml转换为json,我认为它与您使用的包相同:

更新 抱歉,我没有注意到您尝试了@showdev所说的内容

我花了很多时间来寻找问题,但没有找到解决方案,但我发现Angular并没有加载jquery,而不是它总是给我的
undefined


如果你能考虑我提到的NPM软件包,它将解决你的问题。

< P> @戴维的评论奏效了!我想我不能接受评论作为回答,所以我会自己发布:

//app.component.ts

//从“jquery”以$形式导入*是否需要
jquery
?您可能需要先加载jQuery。@showdev是的,但我已经尝试过先加载jQuery。也许它需要完整版本的jQuery,而不是精简版本?@showdev我也尝试过:)先加载jQuery,然后用
声明让$:any替换您的
导入*为$…