我想在app.component.ts文件中使用外部js库中声明的全局变量cwic。js库保存在assets文件夹中,名称为cwic-debug.js。现在,要初始化库并使用cwic变量,必须将语句SystemController方法调用为-
cwic.SystemController.initialize()
index.html
<script type="text/javascript" src="./assets/cwic-debug.js"></script>
我尝试用以下方式初始化cwic库:
app.component.ts-
export class AppComponent implements AfterViewInit{
ngAfterViewInit(){
cwic.SystemController.initialize();
console.log(cwic);
}
title = 'Angular Project';
}
但由于cwic变量没有被识别,它抛出了一个错误,并在cwic单词下划线为红色。
js库,即cwic-debug.js如下所示-
var cwic =
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
如何在app.component.ts文件中使用此cwic变量?
发布于 2018-06-13 05:22:24
您可以声明该变量并将其类型化为any
。
declare var cwic: any;
然后,TypeScript会停下来抱怨变量的类型,并假定它存在,但您将不再从集成开发环境中获得类型帮助。
https://stackoverflow.com/questions/50825981
复制相似问题