I am currently working on a basic application that utilizes Typescript and AngularJS. In my app, I have used 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 setup works perfectly fine for me. Here is how I integrate the code into my project:
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>
Everything seems to be running smoothly so far. I also have a separate file named "secondController.ts", which looks like this:
module myApp {
export class secondController {
constructor($window) {
$window.alert("Second Controller");
}
}
secondController.$inject = ['$window'];
}
Despite having already registered this controller in my app.js (app.ts), changing "ng-controller='CategoryCtrl'" to "ng-controller='secondController'" does not seem to work as expected. Interestingly, if I directly copy the code from secondController.ts-file into my app.ts, everything functions correctly. Unfortunately, I am unable to identify the error and would greatly appreciate any assistance.