0% found this document useful (0 votes)
96 views2 pages

Typescript (1.4) Angularjs (1.4.X) Cheat Sheet

This document provides a cheat sheet for using TypeScript with AngularJS 1.4. It lists Angular services and components that can be used in TypeScript code along with their TypeScript definition interfaces. It also provides examples of how to define a TypeScript controller, module, directive, and route for Angular.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
96 views2 pages

Typescript (1.4) Angularjs (1.4.X) Cheat Sheet

This document provides a cheat sheet for using TypeScript with AngularJS 1.4. It lists Angular services and components that can be used in TypeScript code along with their TypeScript definition interfaces. It also provides examples of how to define a TypeScript controller, module, directive, and route for Angular.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

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

You might also like