我通过打字稿制作了AngularJs应用程序。并使用requireJs load' js(已编译的ts)文件'
我做了简单的控制器A
myCtrl.ts
module myApp {
'use strict';
interface myMessage extends ng.IScope {
message: string;
}
export class myCtrl {
constructor($scope: myMessage) {
$scope.message = "hello world";
}
}
}
我在main.ts中加载myApp文件
myApp.ts
import myController = require('./myCtrl');
module myApp{
'use strict';
angular.module('myApp',[]).controller('myCtrl',myCtrl);
}
angular.bootstrap(document,['myAppDo']);
加载成功但$ scope.message没有改变。
'Cannot read property 'myCtrl' of undefined'
当我更改myApp.ts时,它工作正常
angular.module('myApp', []).controller('myCtrl', ($scope, $http) => {
$scope.message = "hello";
});
angular.bootstrap(document,['myApp']);
我该如何解决?
答案 0 :(得分:1)
我解决了。首先,添加'export'控制器模块
module myApp
到
export module myApp
然后指定路径
import myCtrl = require('./myCtrl');
angular.module('myApp',[]).controller('myCtrl',myCtrl);
到
import myCtrl = require('./myCtrl');
angular.module('myApp',[]).controller('myCtrl',myCtrl.myApp.myCtrl);
似乎有些不对劲,但它有效
答案 1 :(得分:0)
AMD-dependency
///<amd-dependency path="here path to your module"/>
import myController = require('myCtrl');