TypeScript (1.4) AngularJS (1.4.x) Cheat Sheet

Angular TypeScript Definitions: Controllers https://github.com/borisyankov/DefinitelyTyped/tree/master/angularjs $controller ng.IControllerService Resources: Form Controller ng.IFormController Types https://github.com/borisyankov/DefinitelyTyped Model Controller ng.INgModelController TypeScript http://www.typescriptlang.org/ $rootScope ng.IRootScopeService CDN https://code.angularjs.org/ Browser Example: Define a Controller Window ng.IWindowService Browser ng.IBrowserService // undocumented //

Modules private isAlive: boolean = false; private lastCheck: Date = new Date(); Angular global object ng.IAngularStatic Provider ng.IServiceProvider constructor(private $interval: ng.IIntervalService) { Module ng.IModule var intervalFn = () => { this.isAlive = result; this.lastCheck = new Date(); Example: Define a Module };

$interval(intervalFn, 1000); // intervalFn(); module MyModule { } "use strict"; angular.module("myModule", ["ngRoute"]); public static $inject: string[] = ["$interval"]; } export var getModule: () => ng.IModule = () => { return angular.module("myModule"); app.controller("mainCtrl", MainController); } } }

1430 West Peachtree Street, Suite 425 Atlanta, Georgia 30309 678.999.3002 iVision.com TypeScript (1.4) AngularJS (1.4.x) Cheat Sheet

Directives Routes (angular-route.d.ts) Factory ng.IDirectiveFactory Route Service ng.route.IRouteService Directive ng.IDirective Route ng.route.IRoute Route Parameters ng.route.IRouteParamsService Example: Define a Directive (using a factory) Example: Define a Route class MyDirective implements ng.IDirective { public restrict: string = "A"; app.config([ public require: string = "ngModel"; "$routeProvider", ($routeProvider: angular.route.IRouteProvider) => { public = { $routeProvider.when("/My/View/:id", { state: '=' templateUrl: "/My/View", }; controller: "myViewCtrl", controllerAs: "ctrl" constructor(private $location: ng.ILocationService) { }); } } ]); public link: ng.IDirectiveLinkFn = (scope: ng.IScope, element: ng.IAugmentedJQuery, attrs: ng.IAttributes, ngModel: any) => { // do stuff here } Filters } $filter ng.IFilterService var app = getModule(); Custom Filter ng.IFilterProvider app.directive("myDirective", ["$location", ($location: ng.ILocationService) => new MyDirective($location)]); Misc. Logging ng.ILogService Exception Handling ng.IExceptionHandlerService Promise Service ng.IQService Promise ng.IPromise $http ng.IHttpService Injector ng.auto.IInjectorService $provide ng.auto.IProvideService

1430 West Peachtree Street, Suite 425 Atlanta, Georgia 30309 678.999.3002 iVision.com