I've the following AngularJS App written with TypeScript
The Main App where I initalize the App:
module MainApp {
export class App {
public static Module : ng.IModule = angular.module("mainApp", [])
}
}
And my controller
module MainApp {
export class Person {
public firstName: string;
public lastName: string;
}
export interface IMainAppCtrl {
}
export class MainAppCtrl implements IMainAppCtrl {
public person : Person;
constructor() {
this.person = new Person();
this.person.firstName = "Vorname";
this.person.lastName = "Nachname";
}
}
MainApp.App.Module.controller("mainAppCtrl", MainAppCtrl);
}
Thats working, but I am not very happy with this solution, because here I have to register the controller for my App in my controller itself
MainApp.App.Module.controller("mainAppCtrl", MainAppCtrl);
It would be nice If ther is a possiblity to register the controller in the "App" class directly like:
public static Module : ng.IModule = angular.module("mainApp", []).controller("mainAppCtrl", MainAppCtrl);
but thats not working here i get the error Message from the browser
"Argument 'mainAppCtrl' is not a function, got undefined"
in my old plain JS angular controllers I had an mainApp where I've registered all my Controllers like
angular.module("app.main", [
"ui.router",
"ngSanitize",
"DirectiveTestsCtrl",
....
]);
and in my controller i've only registerd the controller name for angular:
angular.module("DirectiveTestsCtrl", [])
.controller("DirectiveTestsCtrl", function () { ... });
is this also possible with the above shown snipes with typescript or what is best practise here - I've searched the web and found many examples but not a good one for controlerAs syntax and with "module Name { class xyz }" which was really working.