简体   繁体   English

Angular导入外部javascript文件,没有导出的成员和编译错误

[英]Angular import external javascript file, getting no exported member and compile errors

I am writing an angular component and got a open source module working with npm install. 我正在编写一个角度组件,并使用npm install开发了一个开源模块。 Now I made some some changes and want to import the javascript file like so 现在我做了一些更改,并希望像这样导入javascript文件

import { ModuleName } from './../../ModuleFolder/ModuleName';

When I place the cursor above the ModuleName inside the bracket, I see the highlighted red error saying Module has not export member ' ModuleName '; 当我将光标放在括号内的ModuleName上方时,我看到突出显示的红色错误,说明模块没有导出成员' ModuleName ';

In my ts code, I have referenced the Module like so 在我的ts代码中,我像这样引用了模块

object: ModuleName ; object: ModuleName ; which is also complaining. 这也是抱怨。

I google and the post says using npm install but I don't want to add this module to my node_module list. 我谷歌和帖子说使用npm安装,但我不想将此模块添加到我的node_module列表。 I am moving the folder out to make my customization. 我正在移动文件夹以进行自定义。

I also tried the following but it is not working 我也试过以下但是没有用

import   './../../ModuleName.bundle.min.js';

I am wondering does the name of the Module needs to be registered somewhere to be able to reference it in my component? 我想知道模块的名称是否需要在某处注册才能在我的组件中引用它?

Thanks for any help. 谢谢你的帮助。

I got external libraries working in Angular by following the following links 我通过以下链接让外部库在Angular中工作

https://hackernoon.com/how-to-use-javascript-libraries-in-angular-2-apps-ff274ba601af https://hackernoon.com/how-to-use-javascript-libraries-in-angular-2-apps-ff274ba601af

Use 'declare' after the import statements 在import语句后使用'declare'

declare const _moduleName;

For example: I am using Swiper.js library using cdn. 例如:我正在使用cdn使用Swiper.js库。 In my angular component, I refer it using a declare keyword. 在我的角度组件中,我使用declare关键字来引用它。

declare const Swiper;

var mySwiper = new Swiper('.swiper-container', { /* ... */ });

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

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