Show Menu
Cheatography

AngularJS 1.x Cheat Sheet (DRAFT) by [deleted]

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

Modules

Define
var mod = angula­r.m­odu­le(­'name', []);

Dependency array is not an optional parameter but can be empty.
Retrieve
var mod = angula­r.m­odu­le(­'na­me');
Config
var mod = angula­r.m­odu­le(­'name', [], function config() { });

- OR -
mod.co­nfi­g(f­unction config() { });

Provider inject­ables only.
Run
mod.ru­n(f­unction run() { });

Standard inject­ables only.
App Module Usage
<body ng-app­="na­me">­</b­ody>

Directives

Define
mod.di­rec­tiv­e('­myD­ire­ctive', functi­on(...) {
  return {
    restrict: 'AEC', // some combin­ation of the three
    scope: {}, // isolate scope
    template: 'some html',
    templateUrl: 'path/to/template',
    replace: true OR false,
    transclue: true OR false,
    require: 'directiveName',
    link: functi­on(­scope, elem, attr, contro­ller, transc­ludeFn) { }
  };
});
Retrieve
mod.di­rec­tiv­e('­myD­ire­cti­ve');
 

Contro­llers

Define
mod.co­ntr­oll­er(­'name', function name() { });

Depend­encies injected by named parameter.
Retrieve
var ctrl = mod.co­ntr­oll­er(­'na­me');
Array Syntax
mod.co­ntr­oll­er(­'name', ['depN­ame', function name(d­epName) { }]);
Controller as Usage
<div ng-con­tro­lle­r="name as vm">­</d­iv>
Standard Usage
<div ng-con­tro­lle­r="n­ame­"­></­div>