【发布时间】:2018-11-22 08:55:11
【问题描述】:
我想使用在 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 变量?
【问题讨论】:
标签: javascript angular angular2-template angular6