\documentclass[10pt,a4paper]{article} % Packages \usepackage{fancyhdr} % For header and footer \usepackage{multicol} % Allows multicols in tables \usepackage{tabularx} % Intelligent column widths \usepackage{tabulary} % Used in header and footer \usepackage{hhline} % Border under tables \usepackage{graphicx} % For images \usepackage{xcolor} % For hex colours %\usepackage[utf8x]{inputenc} % For unicode character support \usepackage[T1]{fontenc} % Without this we get weird character replacements \usepackage{colortbl} % For coloured tables \usepackage{setspace} % For line height \usepackage{lastpage} % Needed for total page number \usepackage{seqsplit} % Splits long words. %\usepackage{opensans} % Can't make this work so far. Shame. Would be lovely. \usepackage[normalem]{ulem} % For underlining links % Most of the following are not required for the majority % of cheat sheets but are needed for some symbol support. \usepackage{amsmath} % Symbols \usepackage{MnSymbol} % Symbols \usepackage{wasysym} % Symbols %\usepackage[english,german,french,spanish,italian]{babel} % Languages % Document Info \author{Greg Finzer (GregFinzer)} \pdfinfo{ /Title (angular.pdf) /Creator (Cheatography) /Author (Greg Finzer (GregFinzer)) /Subject (Angular Cheat Sheet) } % Lengths and widths \addtolength{\textwidth}{6cm} \addtolength{\textheight}{-1cm} \addtolength{\hoffset}{-3cm} \addtolength{\voffset}{-2cm} \setlength{\tabcolsep}{0.2cm} % Space between columns \setlength{\headsep}{-12pt} % Reduce space between header and content \setlength{\headheight}{85pt} % If less, LaTeX automatically increases it \renewcommand{\footrulewidth}{0pt} % Remove footer line \renewcommand{\headrulewidth}{0pt} % Remove header line \renewcommand{\seqinsert}{\ifmmode\allowbreak\else\-\fi} % Hyphens in seqsplit % This two commands together give roughly % the right line height in the tables \renewcommand{\arraystretch}{1.3} \onehalfspacing % Commands \newcommand{\SetRowColor}[1]{\noalign{\gdef\RowColorName{#1}}\rowcolor{\RowColorName}} % Shortcut for row colour \newcommand{\mymulticolumn}[3]{\multicolumn{#1}{>{\columncolor{\RowColorName}}#2}{#3}} % For coloured multi-cols \newcolumntype{x}[1]{>{\raggedright}p{#1}} % New column types for ragged-right paragraph columns \newcommand{\tn}{\tabularnewline} % Required as custom column type in use % Font and Colours \definecolor{HeadBackground}{HTML}{333333} \definecolor{FootBackground}{HTML}{666666} \definecolor{TextColor}{HTML}{333333} \definecolor{DarkBackground}{HTML}{ED1000} \definecolor{LightBackground}{HTML}{FDF0EF} \renewcommand{\familydefault}{\sfdefault} \color{TextColor} % Header and Footer \pagestyle{fancy} \fancyhead{} % Set header to blank \fancyfoot{} % Set footer to blank \fancyhead[L]{ \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{C} \SetRowColor{DarkBackground} \vspace{-7pt} {\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\noindent \hspace*{-6pt}\includegraphics[width=5.8cm]{/web/www.cheatography.com/public/images/cheatography_logo.pdf}} } \end{tabulary} \columnbreak \begin{tabulary}{11cm}{L} \vspace{-2pt}\large{\bf{\textcolor{DarkBackground}{\textrm{Angular Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{Greg Finzer (GregFinzer)} via \textcolor{DarkBackground}{\uline{cheatography.com/15280/cs/10781/}}} \end{tabulary} \end{multicols}} \fancyfoot[L]{ \footnotesize \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{LL} \SetRowColor{FootBackground} \mymulticolumn{2}{p{5.377cm}}{\bf\textcolor{white}{Cheatographer}} \\ \vspace{-2pt}Greg Finzer (GregFinzer) \\ \uline{cheatography.com/gregfinzer} \\ \uline{\seqsplit{www.kellermansoftware.com}} \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Published 6th February, 2017.\\ Updated 29th September, 2023.\\ Page {\thepage} of \pageref{LastPage}. \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Sponsor}} \\ \SetRowColor{white} \vspace{-5pt} %\includegraphics[width=48px,height=48px]{dave.jpeg} Measure your website readability!\\ www.readability-score.com \end{tabulary} \end{multicols}} \begin{document} \raggedright \raggedcolumns % Set font size to small. Switch to any value % from this page to resize cheat sheet text: % www.emerson.emory.edu/services/latex/latex_169.html \footnotesize % Small font. \begin{multicols*}{2} \begin{tabularx}{8.4cm}{x{2 cm} x{6 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Example Project}} \tn % Row 0 \SetRowColor{LightBackground} Angular UI & \seqsplit{https://github.com/GregFinzer/CodePulse.UI} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} .NET Core API & \seqsplit{https://github.com/GregFinzer/CodePulse.API} \tn % Row Count 4 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.28 cm} x{4.72 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Example Component}} \tn % Row 0 \SetRowColor{LightBackground} Example Model & \seqsplit{https://github.com/GregFinzer/CodePulse.UI/blob/main/src/app/features/category/models/add-category-request.model.ts} \tn % Row Count 5 (+ 5) % Row 1 \SetRowColor{white} Example Component HTML & \seqsplit{https://github.com/GregFinzer/CodePulse.UI/blob/main/src/app/features/category/add-category/add-category.component.html} \tn % Row Count 11 (+ 6) % Row 2 \SetRowColor{LightBackground} Example Component TypeScript & \seqsplit{https://github.com/GregFinzer/CodePulse.UI/blob/main/src/app/features/category/add-category/add-category.component.ts} \tn % Row Count 17 (+ 6) % Row 3 \SetRowColor{white} Example Service & \seqsplit{https://github.com/GregFinzer/CodePulse.UI/blob/main/src/app/features/category/services/category.service.ts} \tn % Row Count 22 (+ 5) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{2.4 cm} x{5.6 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Binding}} \tn % Row 0 \SetRowColor{LightBackground} One Way Binding & \textless{}h1\textgreater{}\{\{pageTitle\}\}\textless{}/h1\textgreater{} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} Two Way Binding & \textless{}input {[}(ngModel){]}="customer.FirstName"\textgreater{} \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} Property Binding & \textless{}img {[}src{]}="customer.imageUrl"\textgreater{} \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} Attribute Binding & \textless{}button {[}attr.aria-label{]}="ok"\textgreater{}Ok\textless{}/button\textgreater{} \tn % Row Count 8 (+ 2) % Row 4 \SetRowColor{LightBackground} Class Binding & \textless{}div {[}class.Selected{]}="Selected"\textgreater{}Selected\textless{}/div\textgreater{} \tn % Row Count 10 (+ 2) % Row 5 \SetRowColor{white} ngClass & \textless{}div {[}ngClass{]}="setClasses()"\textgreater{}\{\{nl\}\}~~\{\{customer.name\}\}\{\{nl\}\}\textless{}/div\textgreater{} \tn % Row Count 13 (+ 3) % Row 6 \SetRowColor{LightBackground} Style Binding & button {[}style.color{]}="isSelected ? 'red' : 'white'"\textgreater{} \tn % Row Count 15 (+ 2) % Row 7 \SetRowColor{white} ngStyle & \textless{}div {[}ngStyle{]}="setStyles()"\textgreater{}\{\{nl\}\}~~\{\{customer.name\}\}\{\{nl\}\}\textless{}/div\textgreater{} \tn % Row Count 18 (+ 3) % Row 8 \SetRowColor{LightBackground} Component Binding & \textless{}customer-detail {[}customer{]}="currentCustomer"\textgreater{}\{\{nl\}\}\textless{}customer-detail\textgreater{} \tn % Row Count 21 (+ 3) % Row 9 \SetRowColor{white} Directive Binding & \textless{}div {[}ngClass{]} = "\{selected: isSelected\}"\textgreater{}Customer\textless{}/div\textgreater{} \tn % Row Count 23 (+ 2) % Row 10 \SetRowColor{LightBackground} Event Binding & \textless{}button (click)="save()"\textgreater{}Save\textless{}/button\textgreater{} \tn % Row Count 25 (+ 2) % Row 11 \SetRowColor{white} \$event & \textless{}input {[}value{]}="customer.name"\{\{nl\}\}~(input)="customer.name=\$event.target.value"\textgreater{} \tn % Row Count 29 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{2.56 cm} x{5.44 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Lifecycle Hooks}} \tn % Row 0 \SetRowColor{LightBackground} OnChanges & export class Customer implements OnChanges \{\{\{nl\}\}~~ngOnChanges() \{\}\{\{nl\}\}\} \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} OnInit & export class Customer implements OnInit \{\{\{nl\}\}~~ngOnInit() \{\}\{\{nl\}\}\} \tn % Row Count 7 (+ 3) % Row 2 \SetRowColor{LightBackground} DoCheck & export class Customer implements DoCheck \{\{\{nl\}\}~~ngDoCheck() \{\}\{\{nl\}\}\} \tn % Row Count 10 (+ 3) % Row 3 \SetRowColor{white} \seqsplit{AfterContentInit} & export class Customer implements AfterContentInit \{\{\{nl\}\}~~ngAfterContentInit() \{\}\{\{nl\}\}\} \tn % Row Count 14 (+ 4) % Row 4 \SetRowColor{LightBackground} \seqsplit{AfterContentChecked} & export class Customer implements AfterContentChecked \{\{\{nl\}\}~~ngAfterContentChecked() \{\}\{\{nl\}\}\} \tn % Row Count 18 (+ 4) % Row 5 \SetRowColor{white} \seqsplit{AfterViewInit} & export class Customer implements AfterViewInit \{\{\{nl\}\}~~ngAfterViewInit() \{\}\{\{nl\}\}\} \tn % Row Count 22 (+ 4) % Row 6 \SetRowColor{LightBackground} \seqsplit{AfterViewChecked} & export class Customer implements AfterViewChecked \{\{\{nl\}\}~~ngAfterViewChecked() \{\}\{\{nl\}\}\} \tn % Row Count 26 (+ 4) % Row 7 \SetRowColor{white} OnDestroy & export class Customer implements OnDestroy \{\{\{nl\}\}~~ngOnDestroy() \{\}\{\{nl\}\}\} \tn % Row Count 30 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Component with Inline Template}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{import \{ Component \} from '@angular/core'; \newline \newline @Component(\{ \newline moduleId: module.id, \newline selector: 'customer', \newline template: ` \newline \textless{}h3\textgreater{}\{\{customer.name\}\}\textless{}/h3\textgreater{} \newline ` \newline \}) \newline \newline export class CustomerComponent \{ \newline customer = \{ id: 100, name: 'John Smith' \}; \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{2.96 cm} x{5.04 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Structural Directives}} \tn % Row 0 \SetRowColor{LightBackground} *ngIf & \textless{}div \seqsplit{*ngIf="currentCustomer;else} noCustomerTemplate"\textgreater{}\{\{nl\}\}~~ Selected \{\{currentCustomer.Name\}\}\{\{nl\}\} \textless{}/div\textgreater{}\{\{nl\}\} \textless{}ng-template \#noCustomerTemplate\textgreater{}\{\{nl\}\}~~ No Customer Selected\{\{nl\}\} \textless{}/ng-template\textgreater{} \tn % Row Count 9 (+ 9) % Row 1 \SetRowColor{white} *ngFor & \textless{}ul\textgreater{}\{\{nl\}\}~~\textless{}li *ngFor="let customer of customers"\textgreater{}\{\{nl\}\}~~~~\{\{ customer.name \}\}\{\{nl\}\}~~\textless{}/li\textgreater{}\{\{nl\}\}\textless{}/ul\textgreater{} \tn % Row Count 15 (+ 6) % Row 2 \SetRowColor{LightBackground} *ngSwitch & \textless{}div {[}ngSwitch{]}="orderStatus"\textgreater{}\{\{nl\}\}~~\textless{}template {[}ngSwitchCase{]}="purchased"\textgreater{}\textless{}/template\textgreater{}\{\{nl\}\}~~\textless{}template {[}ngSwitchCase{]}="shipped"\textgreater{}\textless{}/template\textgreater{}\{\{nl\}\}~~\textless{}template {[}ngSwitchDefault{]}\textgreater{}\textless{}/template\textgreater{}\{\{nl\}\}\textless{}/div\textgreater{} \tn % Row Count 25 (+ 10) % Row 3 \SetRowColor{white} Create Custom Directive & ng generate directive \textless{}directive name\textgreater{} \tn % Row Count 27 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.04 cm} x{4.96 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Pipes}} \tn % Row 0 \SetRowColor{LightBackground} Async & \textless{}ng-container *ngIf="customers\$ | async as customers"\textgreater{}\{\{nl\}\} ~~\textless{}span *ngFor="let customer of customers"\textgreater{}\{\{customer.firstName\}\}\textless{}/span\textgreater{}\{\{nl\}\} \textless{}/ng-container\textgreater{} \tn % Row Count 7 (+ 7) % Row 1 \SetRowColor{white} Currency & \textless{}p\textgreater{}\{\{price | currency\}\}\textless{}/p\textgreater{} \tn % Row Count 9 (+ 2) % Row 2 \SetRowColor{LightBackground} Date & \textless{}p\textgreater{}\{\{orderDate | date:'medium'\}\}\textless{}/p\textgreater{} \tn % Row Count 11 (+ 2) % Row 3 \SetRowColor{white} Date Format & \textless{}p\textgreater{}\{\{orderDate | date:'yMMMd''\}\}\textless{}/p\textgreater{} \tn % Row Count 13 (+ 2) % Row 4 \SetRowColor{LightBackground} Decimal & \textless{}p\textgreater{}\{\{ 12345.6789 | number:'3.1-2' \}\}\textless{}/p\textgreater{} \tn % Row Count 15 (+ 2) % Row 5 \SetRowColor{white} JSON Debugging & \textless{}pre\textgreater{}\{\{Customer | json\}\}\textless{}/pre\textgreater{} \tn % Row Count 17 (+ 2) % Row 6 \SetRowColor{LightBackground} Key Value (Object or Map) & \textless{}div *ngFor="let item of objectData | keyvalue"\textgreater{}\{\{nl\}\} ~~\{\{ item.key \}\}: \{\{ item.value \}\}\{\{nl\}\} \textless{}/div\textgreater{} \tn % Row Count 22 (+ 5) % Row 7 \SetRowColor{white} Lower Case & \textless{}p\textgreater{}\{\{customer.name | lowercase\}\}\textless{}/p\textgreater{} \tn % Row Count 24 (+ 2) % Row 8 \SetRowColor{LightBackground} Number & \textless{}p\textgreater{}value | number:'1.1-2'\}\}\textless{}/p\textgreater{} \tn % Row Count 26 (+ 2) % Row 9 \SetRowColor{white} Percent & \textless{}p\textgreater{}\{\{taxes | percent:'1.1-1'\}\}\textless{}/p\textgreater{} \tn % Row Count 28 (+ 2) % Row 10 \SetRowColor{LightBackground} Title Case & \textless{}p\textgreater{}\{\{ 'hello world' | titlecase \}\}\textless{}/p\textgreater{} \tn % Row Count 30 (+ 2) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{3.04 cm} x{4.96 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Pipes (cont)}} \tn % Row 11 \SetRowColor{LightBackground} Upper Case & \textless{}p\textgreater{}\{\{customer.name | uppercase\}\}\textless{}/p\textgreater{} \tn % Row Count 2 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Component Linked Template}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{import \{ Component \} from '@angular/core'; \newline \newline @Component(\{ \newline moduleId: module.id, \newline selector: 'customer', \newline templateUrl: \seqsplit{'customer.component.html'}, \newline styleUrls: {[}'customer.component.css'{]} \newline \}) \newline \newline export class CustomerComponent \{ \newline customer = \{ id: 100, name: 'John Smith' \}; \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}