Here is a quick reference cheat sheet for you to familiarize yourself with common Angular syntax and CLI commands. Take some time to review and orient yourself with new Angular syntax, major components, CLI scaffolds, and common pipes.
You may find the list especially useful if your background is with AngularJS, since you will need to unlearn some old syntax.
If you are new to Angular or simply not a fan of CLI commands, check out Nx Console at https://nx.dev/angular/cli/console, an awesome desktop app, and a Visual Studio Code extension, that can write your CLI arguments for you. That said, I do recommend that you first gain familiarity with the CLI commands and force yourself to use them for a bit, so you have a better understanding of how Nx Console works.
Binding, or data binding, refers to an automatic one or two-way connection between a variable in code and a value displayed or inputted in an HTML template or another component:
Type | Syntax | Data direction |
Interpolation Property Attribute Class Style |
|
One-way, from data source to view target |
Event |
|
One-way, from view target to data source |
Two-way |
|
Two-way |
Directives encapsulate coded behaviors that can be applied as attributes to HTML elements or other components:
Pipes (known as filters in AngularJS) modify how a data-bound value is displayed in an HTML template:
Name | Purpose | Usage |
Async |
Manages subscriptions to observables, and provides synchronous access to the variable in the template |
|
Date |
Formats a date according to locale rules |
|
Text Transformation |
Transforms text to uppercase, lowercase, or title case |
|
Decimal |
Formats a number according to locale rules |
|
Percent |
Formats a number as a percentage according to locale rules |
|
Currency |
Formats a number as currency with a currency code and symbol according to locale rules |
|
Starter commands help generate new projects or add dependencies. Angular CLI commands help create major components by automatically generating boilerplate scaffolding code with ease. For the list of the full set of commands, visit https://github.com/angular/angular-cli/wiki.
Here are the most basic commands, which you will probably memorize over time and use the most often. Remember never to install @angular/cli
globally as covered in Chapter 3, Creating a Basic Angular App:
Name | Purpose | CLI command |
New |
Creates a new Angular application with an initialized Git repository, |
|
Update |
Updates Angular, RxJS, and Angular Material dependencies. Rewrites code, if necessary, to maintain compatibility. |
|
Add Material |
Installs and configures Angular Material dependencies. |
|
Use the following commands during your daily workflow to add new components, services, and other major components to your Angular application. These commands will save you serious time and help you avoid simple configuration mistakes:
In order to properly scaffold some of the components listed earlier under a custom module, such as my-module
, you can prepend the module name before the name of what you intend to generate, for example, ng g c my-module/my-new-component
. The Angular CLI will properly wire up and place the new component under the my-module
folder.
If you are not familiar with the TypeScript syntax, these TypeScript-specific scaffolds will help you create classes, interfaces, and enums, so you can leverage object-oriented programming principles to reduce the duplication of code and implement code behavior like calculated properties in classes rather than components:
Name | Purpose | CLI command |
Class |
Creates a barebones class |
|
Interface |
Creates a barebones interface |
|
Enum |
Creates a barebones enum |
|
In order to become an effective Angular developer, you need to become an RxJS master. Here are some of the most common and useful RxJS operators for quick reference:
Name | Purpose |
|
Takes one or more observables as input and generates an observable as output, allowing you to build custom data streams. |
|
Required to activate an observable. It is an anti-pattern to extract the value of an observable data stream from a |
|
Releases resources and cancels observable executions. Not unsubscribing can lead to performance problems and memory leaks. Use the Async pipe or the |
Thanks to Jan-Niklas Wortmann for reviewing this section. Keep up with him on Twitter: @niklas_wortmann
.