简体   繁体   中英

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. Now I made some some changes and want to import the javascript file like so

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 ';

In my ts code, I have referenced the Module like so

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. 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

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

Use 'declare' after the import statements

declare const _moduleName;

For example: I am using Swiper.js library using cdn. In my angular component, I refer it using a declare keyword.

declare const Swiper;

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

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