我试图创建一个简单的TypeScript类,但是当它被实例化时,我收到一个
this is undefined
构造函数中存在错误。
类别:
class MyClass {
stuff: string;
constructor(){
this.stuff = 'stuff';
}
}
app.config([MyClass]);
编译为:
var MyClass = (function () {
function MyClass() {
this.stuff = 'stuff';
}
return MyClass;
}());
app_module_1.app.config([MyClass]);
为什么这不起作用?为什么是
this
未定义?基于我编写的示例和其他代码,这似乎是合适的语法。
我代码的其余部分(有效):
export let app = angular.module('timeApp', [
uirouter
]);
class MainController{
stuff: string;
constructor(){
this.stuff = "TESTING";
}
}
app.controller('mainController', MainController);