AngularJS (Angular 1.x) is a JavaScript-based structural framework developed by Google for building dynamic single-page applications (SPAs). It extends HTML's syntax with directives and enables two-way data binding between models and views, allowing the DOM to update automatically when data changes. AngularJS 1.8.3 (released December 2021) is the final official version, having reached end-of-life on December 31, 2021, yet it remains widely encountered in legacy codebases. Understanding AngularJS's declarative approach β where you describe what the UI should do rather than how to manipulate the DOM β is crucial for maintaining existing applications and recognizing the patterns that influenced modern frameworks.
What This Cheat Sheet Covers
This topic spans 19 focused tables and 204 indexed concepts. Below is a complete table-by-table outline of this topic, spanning foundational concepts through advanced details.
Table 1: Core Directives - Data Binding and Display
| Directive | Example | Description |
|---|---|---|
<input ng-model="username"> | β’ Binds input, select, or textarea value to a scope property β’ enables two-way data binding where changes in view update model and vice versa | |
<span ng-bind="message"></span> | β’ One-way binds scope expression to element's text content β’ faster initial render than {{ }} interpolation as it avoids brief flash of uncompiled markup | |
<div ng-bind-html="trustedHtml"></div> | β’ Binds and renders HTML content from scope expression β’ requires ngSanitize module or $sce.trustAsHtml() to mark content safe | |
<h1>{{title}}</h1> | β’ Embeds expressions directly in HTML β’ supports filters and one-time binding with {{::expression}} prefix | |
<li ng-repeat="item in items"> {{item.name}}</li> | β’ Instantiates template once per item in collection β’ creates child scope for each iteration with $index, $first, $last, $even, $odd properties | |
<select ng-model="sel" ng-options="x.name for x in items"></select> | β’ Dynamically generates <option> elements for a <select> from array or objectβ’ more efficient than ng-repeat on <option> | |
<div ng-if="isVisible"> Content</div> | β’ Adds or removes element from DOM based on expression β’ creates new scope when true; better performance for heavy conditional content than ng-show | |
<p ng-show="isActive">Text</p> | β’ Shows or hides element by adding/removing .ng-hide CSS class (display: none)β’ element remains in DOM; faster toggling than ng-if | |
<p ng-hide="isHidden">Text</p> | β’ Hides or shows element β’ inverse of ng-show; applies .ng-hide when expression is true | |
<div ng-switch="status"> <p ng-switch-when="active">Active</p> <p ng-switch-default>Other</p></div> | β’ Conditionally swaps DOM structure based on expression β’ uses ng-switch-when for cases and ng-switch-default for fallback | |
<ng-pluralize count="itemCount" when="{'0':'No items','1':'1 item','other':'{} items'}"></ng-pluralize> | Displays locale-aware plural message based on numeric count using en-US pluralization rules |