Last active
December 15, 2015 15:19
-
-
Save mauricedb/5280482 to your computer and use it in GitHub Desktop.
AngularJS controller using TypeScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <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