Skip to content

Instantly share code, notes, and snippets.

@mauricedb
Last active December 15, 2015 15:19
Show Gist options
  • Save mauricedb/5280482 to your computer and use it in GitHub Desktop.
Save mauricedb/5280482 to your computer and use it in GitHub Desktop.
AngularJS controller using TypeScript
/// <reference path="../Scripts/typings/angularjs/angular.d.ts" />
module App {
export class TestCtrl {
private startTime: string;
constructor(private $scope: ITestCtrlScope) {
this.startTime = new Date().toLocaleString();
$scope.message = "Hello there at " + this.startTime;
// Make sure this is scopped to the controller in the btnClick function
$scope.btnClick = angular.bind(this, this.btnClick);
}
btnClick($scope: any) {
$scope.message = "Clicked from " + this.startTime;
this.fn();
}
fn() {
alert("Clicked from " + this.startTime);
}
}
export interface ITestCtrlScope extends ng.IScope {
message: string;
btnClick: Function;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment