AngularJS VS2015中TypeScript ts文件的顺序问题appBundle.js
The sequence issue of AngularJS TypeScript ts files in VS2015 appBundle.js
我正在使用 VS2015 RC Cordova TypeScript 项目学习 AngularJS 和 TypeScript。
我使用以下代码在 "index.ts" 的同一文件夹中添加了一个 "MyController.ts" 文件,效果很好。
module MyTestApp{
export class MyController
{
constructor( $scope )
{
$scope.message = { title: "Hello World!!" };
}
}
}
var myApp = angular.module( 'myTestApp', [] );
myApp.controller( 'myController', MyTestApp.MyController );
但是,当我在 "MyController.ts"
的同一文件夹中添加另一个文件 "YourController.ts" 时
module MyTestApp{
export class YourController
{
constructor( $scope )
{
$scope.message = { title: "Hello World!!" };
}
}
}
然后在 MyController.ts 的最后一行添加此代码,因为需要在 angular 模块中添加控制器。
myApp.controller( 'myController', MyTestApp.YourController);
我编译的项目没问题,但是 运行 它有错误消息。
原来这些ts文件都会按照ts文件的字母顺序依次编译成"appBundle.js"。
所以原因是“YourController.ts”在“MyController.ts”下面,这一行
myApp.controller( 'myController', MyTestApp.YourController);
在 "appBundle.js" 文件中找不到上述代码下的 "YourController"。
我知道这是因为 javascript 是一种顺序 运行 的脚本语言,我可以在 "YourController.ts".
中剪切和粘贴以下代码
var myApp = angular.module( 'myTestApp', [] );
myApp.controller( 'myController', MyTestApp.MyController );
myApp.controller( 'myController', MyTestApp.YourController);
但是如果下次我添加另一个控制器时,说“ZooController.ts”,我应该将以上所有代码移到“[=”的最后一行51=]ZooController.ts"?
谁能告诉我上面的代码应该放在哪里?
非常感谢。
不建议使用自动捆绑,因为 out
会在此处记录一些不良后果:https://github.com/TypeStrong/atom-typescript/blob/master/docs/out.md
那是说您可以使用 grunt-ts
之类的东西来减轻疼痛:https://github.com/TypeStrong/grunt-ts#javascript-generation
我正在使用 VS2015 RC Cordova TypeScript 项目学习 AngularJS 和 TypeScript。
我使用以下代码在 "index.ts" 的同一文件夹中添加了一个 "MyController.ts" 文件,效果很好。
module MyTestApp{
export class MyController
{
constructor( $scope )
{
$scope.message = { title: "Hello World!!" };
}
}
}
var myApp = angular.module( 'myTestApp', [] );
myApp.controller( 'myController', MyTestApp.MyController );
但是,当我在 "MyController.ts"
的同一文件夹中添加另一个文件 "YourController.ts" 时module MyTestApp{
export class YourController
{
constructor( $scope )
{
$scope.message = { title: "Hello World!!" };
}
}
}
然后在 MyController.ts 的最后一行添加此代码,因为需要在 angular 模块中添加控制器。
myApp.controller( 'myController', MyTestApp.YourController);
我编译的项目没问题,但是 运行 它有错误消息。
原来这些ts文件都会按照ts文件的字母顺序依次编译成"appBundle.js"。 所以原因是“YourController.ts”在“MyController.ts”下面,这一行
myApp.controller( 'myController', MyTestApp.YourController);
在 "appBundle.js" 文件中找不到上述代码下的 "YourController"。
我知道这是因为 javascript 是一种顺序 运行 的脚本语言,我可以在 "YourController.ts".
中剪切和粘贴以下代码 var myApp = angular.module( 'myTestApp', [] );
myApp.controller( 'myController', MyTestApp.MyController );
myApp.controller( 'myController', MyTestApp.YourController);
但是如果下次我添加另一个控制器时,说“ZooController.ts”,我应该将以上所有代码移到“[=”的最后一行51=]ZooController.ts"?
谁能告诉我上面的代码应该放在哪里?
非常感谢。
不建议使用自动捆绑,因为 out
会在此处记录一些不良后果:https://github.com/TypeStrong/atom-typescript/blob/master/docs/out.md
那是说您可以使用 grunt-ts
之类的东西来减轻疼痛:https://github.com/TypeStrong/grunt-ts#javascript-generation