angular-typescript-cheatsheet
module services {
//...
class MyService {
//...
}
angular.module('services', ['dependency']).service('MyService', MyService);
}
inside a class:
class MainCtrl {
static $inject = ['$scope', 'MyAnimalFactory'];
constructor($scope: ng.IScope, factory: MyAnimalFactory) {
//...
}
}
class MainCtrl {
name: string = 'default';
list: Array<Animal> = [];
constructor() {
this.name = 'dog';
}
}
module services {
//more classes: ...
class AnimalFactory {
//... more classes
getInstance(type: string, name: string) {
var clazz = null;
if(type === 'mammal') {
clazz = Mammal;
} else if(type === 'reptile') {
clazz = Reptile;
} else {
clazz = Animal;
}
return new clazz(name);
}
}
angular.module('animals',[]).service('MyAnimalFactory', AnimalFactory);
}
//Usage:
//...
static $inject = ['$scope', 'MyAnimalFactory'];
//...
var isDone: boolean = false;
var height: number = 6;
var name: string = 'bob';
var list: Animal[] = [];
var list: Animal[];
enum Color {Red, Green, Blue};
function warn(): void {
//...
}
interface Being {
name: string;
live();
}
interface IProjectsScope extends ng.IScope {
}