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
Angular CDN https://code.angularjs.org/
Browser Example: Define a Controller
Window ng.IWindowService
Browser ng.IBrowserService // undocumented // <reference path="../../typings/angularjs/angular.d.ts"/>
module MyModule {
Document ng.IDocumentService
"use strict";
$timeout ng.ITimeoutService
$interval ng.IIntervalService var app = getModule();
$location ng.ILocationService
class MainController {
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);
// <reference path="../typings/angularjs/angular.d.ts"/> 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)
Directive 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 scope = { $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<T>
$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