Skip to content

jepetko/angular-typescript-cheatsheet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 

Repository files navigation

angular-typescript-cheatsheet

module

module services {

  //...
  class MyService {
    //...
  }
  
  angular.module('services', ['dependency']).service('MyService', MyService);  
}

dependency injection

inside a class:

class MainCtrl {

  static $inject = ['$scope', 'MyAnimalFactory'];
  
  constructor($scope: ng.IScope, factory: MyAnimalFactory) {
    //...
  }
}

class

class MainCtrl {
  name: string = 'default';
  list: Array<Animal> = [];
  
  constructor() {
    this.name = 'dog';
  }
}

service

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'];
//...

types

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 {
   //...
}

interfaces

interface Being {
  name: string;
  live();
}
interface IProjectsScope extends ng.IScope {
}

About

Angular Typescript Cheatsheet

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published