admin管理员组文章数量:1295112
I have a global variable declared in the html header and want to reference it from a class inside a module. How can I prevent piler error:
error TS2095: Could not find symbol 'selfGlobal'.
<html>
<head>
<script>
var selfGlobal = this;
var globalVariable = 1;
</script>
</head>
<body>
<script src="test.js"></script>
</body>
</html>
In test.ts
module Test{
export class TestClass {
private _privateVariable:any;
constructor() {
this._privateVariable = selfGlobal.globalVariable; // pile error throws here, but the code can run
}
}
}
Thanks! Mars
I have a global variable declared in the html header and want to reference it from a class inside a module. How can I prevent piler error:
error TS2095: Could not find symbol 'selfGlobal'.
<html>
<head>
<script>
var selfGlobal = this;
var globalVariable = 1;
</script>
</head>
<body>
<script src="test.js"></script>
</body>
</html>
In test.ts
module Test{
export class TestClass {
private _privateVariable:any;
constructor() {
this._privateVariable = selfGlobal.globalVariable; // pile error throws here, but the code can run
}
}
}
Thanks! Mars
Share Improve this question edited Jul 20, 2013 at 17:01 Mars Zhu asked Jul 20, 2013 at 16:55 Mars ZhuMars Zhu 2962 silver badges14 bronze badges 1- 1 See also stackoverflow./questions/13252225/… – koppor Commented May 14, 2016 at 22:24
1 Answer
Reset to default 10You need to tell the piler it has been declared:
declare var selfGlobal: any;
本文标签: javascriptReference to global variable from a moduleStack Overflow
版权声明:本文标题:javascript - Reference to global variable from a module - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741610463a2388227.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论