Show Menu
Cheatography

AngularJS Cheat Sheet (DRAFT) by

The very basics of AngularJS

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Module Setup

var app = angula­r.m­odu­le(­'My­App', []);

Controller Setup

app.co­ntr­oll­er(­'Ma­inC­ont­rol­ler', ['$scope', functi­on(­$scope) { }]);

Core Directives

Attach a Module to HTML
<body ng-con­troller = "­MyA­pp">


Attach a Controller to HTML
<div ng-con­tro­lle­r="M­ain­Con­tro­lle­r">


Iterate through an array
<div ng-rep­eat­="item in items">
 

Directive Template

app.di­rec­tiv­e('­MyD­ire­ctive', function() { 

  return { 

    restrict: 'E', 

    scope: { 

      info: '=' 

    }, 

    templa­teUrl: 'js/di­rec­tiv­es/­myD­ire­cti­ve.h­tml' 

  }; 

});