Javascript 在Angular中导入其他变量之前,如何从第三部分脚本导入全局变量?

Javascript 在Angular中导入其他变量之前,如何从第三部分脚本导入全局变量?,javascript,angular,typescript,codemirror,Javascript,Angular,Typescript,Codemirror,我正在玩ot.js和带有Angular 4的CodeMirror编辑器。不幸的是,我在将ot.js的一些组件导入Angular 4组件时遇到了问题 ot.js源代码- 看起来ot.js的某些组件需要在导入之前定义全局变量。请参阅下面的代码: /*下一行从ot.js导入以下js文件: ../ot/lib/editor-socketio-server.js ../ot/lib/index.js ../ot/lib/selection.js ../ot/lib/text-operation.js .

我正在玩ot.js和带有Angular 4的CodeMirror编辑器。不幸的是,我在将ot.js的一些组件导入Angular 4组件时遇到了问题

ot.js源代码-

看起来ot.js的某些组件需要在导入之前定义全局变量。请参阅下面的代码:

/*下一行从ot.js导入以下js文件:
../ot/lib/editor-socketio-server.js
../ot/lib/index.js
../ot/lib/selection.js
../ot/lib/text-operation.js
../ot/lib/server.js
../ot/lib/simple-text-operation.js
../ot/lib/wrapped-operation.js
../ot/lib/client.js
*/
从“ot”导入*作为ot
//这似乎需要在导入此文件之前定义“ot”全局变量。看起来“CodeMirrorAdapter”已连接到“ot”
导入“ot/lib/codemirror适配器”
@组成部分({
选择器:'应用程序根',
templateUrl:“./app.component.html”,
样式URL:['./app.component.css']
})
导出类AppComponent实现AfterViewInit{
@ViewChild(“编辑器”)编辑器;
//如果未定义“codemirror adapter”导入:ot变量,则此操作正常
otClient=新的ot.Client(0);
//此操作失败,错误如下:未定义ot
cma=new ot.CodeMirrorAdapter(this.editor.instance);
...

}
你试过这种方法吗

declare var require: any; 
const ot = require('ot'); 
然后导入其他东西

import .... 

你试过这种方法吗

declare var require: any; 
const ot = require('ot'); 
然后导入其他东西

import .... 

我解决了同样的问题<代码>声明常量:任意

我解决了相同的问题
declare const ot:any

诀窍是将定义
ot
变量的文件添加到
.angular cli.json

"scripts": [
  "../node_modules/ot/lib/client.js",
  "../node_modules/ot/lib/text-operation.js"
],

感谢@Jong Hyun Kim让我回到这条轨道。

诀窍是将定义
ot
变量的文件添加到
.angular cli.json的“脚本”部分

"scripts": [
  "../node_modules/ot/lib/client.js",
  "../node_modules/ot/lib/text-operation.js"
],

感谢@Jong Hyun Kim将我带回这条赛道。

@Alex,不幸的是,在我的ot.js导入之前添加这条赛道没有任何帮助。错误是sameit也没有看到任何导入/要求的组合遵循此想法:(@Alex,不幸的是,在my ot.js导入之前添加此组合没有帮助。错误是sameit也没有看到导入/要求遵循此想法的任何组合:(不幸的是,在我的ot.js导入之前添加此声明没有帮助。错误保持不变。是否在angular.json中添加了ot.js?
“scripts”:[“./node_modules/jquery/dist/jquery.min.js”,]
像这样。我以前尝试过,但突然它起了作用。诀窍是添加声明
ot
变量的脚本。我通常更喜欢此库的lazy init,但在特定情况下它是可以的。谢谢!不幸的是,在我的ot.js导入之前添加此声明没有帮助。错误保持不变。是否在导入时添加了ot.jsangular.json?
“scripts”:[“./node\u modules/jquery/dist/jquery.min.js”,]
像这样。我以前试过,但突然它起了作用。诀窍是添加声明
ot
变量的脚本。我通常更喜欢这个库的lazy init,但在给定的情况下,它没问题。谢谢!