我正在尝试使用requireJS将外部类(用Typescript编写)导入另一个Typescript类。我使用了这种语法,但是我不明白为什么我在此import语句中遇到语法错误:
我也尝试使用它来代替:
import t = module("Controller/TestController");
而且我也遇到同样的错误。
上面的import/require语句驻留在
appmod.ts
中。这是我的文件结构:+Root
+Scripts
+app
-main.ts
-appmod.ts
+Controller
-TestController.ts
我仔细阅读了文档,对我来说这行看起来很完美。路径中确实存在文件TestController.ts,并且类的前面带有export关键字。
这条线怎么了?
这是我的TestController.ts的样子:
/// <reference path="../typings/angularjs/angular.d.ts" />
module testApp.Controller {
export interface ITestScope extends ng.IScope {
helloString:string;
}
export class TestController {
public static $inject = [
"$scope"
];
constructor(private $scope: ITestScope) {
this.$scope.helloString = "Hello!";
}
}
}
我在TestController.js中使用了DefinitelyTyped的AngularJS定义。
最佳答案
您的导出语句必须位于文件的根目录级别。删除冗余模块http://m.youtube.com/watch?v=KDrWLMUY0R0&hd=1
IE。删除'module testApp.Controller'