Tôi có một biến toàn cục được khai báo trong tiêu đề html và muốn tham chiếu biến đó từ một lớp bên trong một mô-đun. Làm cách nào để ngăn chặn lỗi trình biên dịch:Tham chiếu đến biến toàn cục từ một mô-đun
lỗi TS2095: Không thể tìm thấy biểu tượng 'selfGlobal'.
<html>
<head>
<script>
var selfGlobal = this;
var globalVariable = 1;
</script>
</head>
<body>
<script src="test.js"></script>
</body>
</html>
Trong test.ts
module Test{
export class TestClass {
private _privateVariable:any;
constructor() {
this._privateVariable = selfGlobal.globalVariable; // compile error throws here, but the code can run
}
}
}
Cảm ơn! Mars
Xem thêm http://stackoverflow.com/questions/13252225/call-a-global-variable-inside-typescript-module – koppor