简体   繁体   English

如何在Angular 7项目中使用外部js库函数?

[英]How to use external js library functions in Angular 7 project?

We are creating one project in angular 7. We want to use jquery based library as image picker. 我们正在用angular 7创建一个项目。我们想使用基于jquery的库作为图像选择器。

We have imported the library correctly as import * as 'image-picker' from '..asset/image-picker.min.js' 我们已经从'..asset / image-picker.min.js'中正确导入了库作为import * as'image-picker'

Also it has been imported as script in index.js with correct path. 此外,它已以正确的路径作为脚本导入到index.js中。

Now we are getting stuck about the correct use of this file in Typescript environment. 现在,我们被困在Typescript环境中正确使用此文件。 For example how to use the below example method of the above library in Angular Module in component and templates. 例如,如何在组件和模板的Angular Module中使用上述库的以下示例方法。

You CANNOT use jquery based libs in Angular context. 您不能在Angular上下文中使用基于jquery的库。 It was clearly not a good practice with the old fashionned AngularJS 1.**, now it's not even possible. 显然,使用老式的AngularJS 1。**不是一个好习惯,现在甚至是不可能的。

EDIT : 编辑:

According to this source , it's seem's possible. 根据此消息来源 ,这似乎是有可能的。 But for me, it's clearly not a good idea to insist on using Jquery with Angular 7 但是对我来说,坚持在Angular 7中使用Jquery显然不是一个好主意

I saw this library using jquery so If you using external library you need to include script of that library in your website using script tag or if you using angular cli you need to edit your angular.json and include that script 我使用jquery看到了这个库,因此,如果您使用外部库,则需要使用script标签在网站中包含该库的脚本,或者如果您使用angular cli,则需要编辑angular.json并包含该脚本

then use it in your method 然后在你的方法中使用它

$("select").imagepicker()

You can go to my blog to read detail how to integrate third party library to angular here 您可以在我的博客上阅读有关如何将第三方库集成到Angular的详细信息

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

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