I have a simple application using Typescript and angular JS. I use the app.js to register my controller and some route parameters:
/// <reference path="../scripts/typings/angularjs/angular.d.ts" />
/// <reference path="secondController.ts" />
/// <reference path="../scripts/typings/angularjs/angular-route.d.ts" />
module myApp {
export class Config {
constructor($routeProvider: ng.route.IRouteProvider) {
$routeProvider.when("/add", { templateUrl: "test.html", controller: "CategoryCtrl" })
.when("/add2", { templateUrl: "test.html", controller: "secondController" })
.otherwise({ redirectTo: '/list' });
}
}
Config.$inject = ['$routeProvider'];
export class CategoryCtrl {
constructor($window) {
$window.alert("Hi from CategoryCtrl");
}
}
CategoryCtrl.$inject = ['$window'];
var app = angular.module("myApp", ['ngRoute']);
app.config(Config);
app.controller('CategoryCtrl', CategoryCtrl);
app.controller('secondController', secondController);
}
This works fine. Here some snipped, how I use the code:
div class="container" style="margin-top:10px;">
<div class="col-md-3" ng-controller="CategoryCtrl">
<a href="#/add" style="color:blue; font-weight:bold;">Add New Video</a><br />
<a href="#/add2" style="color:blue; font-weight:bold;">Add New Video2</a>
</div>
So far, so good. I have another file, called "secondController.ts", which looks like:
module myApp {
export class secondController {
constructor($window) {
$window.alert("Second Controller");
}
}
secondController.$inject = ['$window'];
}
As You can see, I already registered this controller in my app.js (app.ts), but if I change the "ng-controller='CategoryCtrl'" to "ng-controller='secondController'" this doesn't work. If I just copy the code from the secondController.ts-file to my app.ts, there is no problem.... I don't see the error and I would be grateful for any help.