在angular4的app.component.ts文件中使用外部库变量

Using external library variable in app.component.ts file in angular4

我想在app.component.ts文件中使用在外部js库中声明的全局变量cwic。 js 库作为 cwic-debug.js 保存在 assets 文件夹中。现在要初始化库并使用 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 变量?

您可以声明变量并将其键入 any

declare var cwic: any;

TypeScript 将停止抱怨变量的类型并假设它存在,但您将不再从 IDE.

获得类型帮助