简体   繁体   English

在 angular 中使用声明的模块时找不到名称

[英]Can't find name when using a declared module in angular

I am using Angular and I would like to add scriptJS to my project in order to load some script dynamically.我正在使用 Angular 并且我想将 scriptJS 添加到我的项目中以便动态加载一些脚本。

I installed scriptjs我安装了脚本

npm i scriptjs npm install -D @types/scriptjs npm i scriptjs npm install -D @types/scriptjs

Now, the types are defined like this现在,类型定义如下

declare module 'scriptjs'{ 
    var $script: $script; 
    export = $script; 
}

but when I do但是当我这样做的时候

$script('blabla.js', function () {}) 

I am prompted with Can't find name $script .我收到提示Can't find name $script

I already added other @types package to my project and they are correctly found, but I still struggle when using package that extend the global scope.我已经在我的项目中添加了其他@types package,并且可以正确找到它们,但是在使用扩展全局 scope 的 package 时,我仍然很挣扎。

I managed to use it, but I had to import it at the beginning of the file before using it.我设法使用它,但在使用它之前我必须在文件的开头导入它。
import * as $script from "scriptjs";

Also, I saw another similar question, and it looks like you can import only the function you need https://stackoverflow.com/a/53026833/14079026另外,我看到了另一个类似的问题,看起来你只能导入你需要的function https://stackoverflow.com/a/53026833/14079026

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

相关问题 在Angular 6中找不到名称 - Can't find Name in Angular 6 angular 在重建之前找不到模块 - angular can't find module untill rebuild 无法使用@ViewChildren选择在Angular 2的模板中声明的组件 - Can't select component declared in a template for Angular 2 using @ViewChildren 使用全局模块声明时无法识别Angular Service - Angular Service not recognized when declared with global module 尽管已在我的模块的 entryComponents 选项中声明了我的组件,但 Angular 如何找不到它的组件工厂? - How Angular can not find the component factory for my component despite it has been declared in the entryComponents option of my Module? 在 Angular 项目中尝试导入 SDK 时找不到模块或其对应的类型声明 - Can't find module or its corresponding type declarations when trying to import SDK in Angular Project 从其他模块角度找不到组件 - Can't find component from other module angular 为什么在我使用angularAMD的模块中找不到“ angular”? - Why I can't find 'angular' in in a module with angularAMD? ReferenceError:在角度测试中找不到变量:模块 - ReferenceError: Can't find variable: module in angular testing AngularJS网页找不到引用的Angular模块或控制器 - AngularJS Webpage Can't Find Referenced Angular Module or Controller
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM