从打字稿中访问HTML标头中包含的javascript变量 [英] Access javascript variable included in HTML header from typescript
问题描述
我的Angular 2应用程序的< head></head>
标记中包含一个javascript文件.我想从我的打字稿文件访问该javascript文件中的函数,该怎么办?当我运行该应用程序时,可以在浏览器控制台中键入 var simplemde = new SimpleMDE()
来使Markdown编辑器正常工作,但是如何在Typescript文件的构造函数中做到这一点呢?
I have a javascript file included in the <head></head>
tags of my Angular 2 app. I would like to access a function in that javascript file from my typescript file, how should I do that? When I'm running the app, I can type var simplemde = new SimpleMDE()
in the browser console to get my markdown editor working, but how can I do this in the constructor in my typescript file?
推荐答案
只需在组件顶部或需要的地方声明它,就像这样:
Just declare it at the top of your component or wherever you need it like so:
declare var SimpleMDE: any;
然后,您可以根据需要在构造函数中调用它!
Then you can call it in your constructor like you want!
这篇关于从打字稿中访问HTML标头中包含的javascript变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!