This is a draft cheat sheet. It is a work in progress and is not finished yet.
Setup
npm i -g @angular/cli |
Install latest version |
ng -v |
check your CLI version |
ng --help |
show all commands in terminal |
ng doc (component) |
open Angular documentation |
Main Commands
ng new |
ng new myApp |
create a new project |
ng serve |
ng s -o |
compile and open |
ng generate |
ng g |
create new component/route/service |
ng build |
ng b |
build for deployment in dist folder |
ng test |
|
test spec files |
ng e2e |
ng e |
end-to-end tests |
ng lint |
ng l |
run linting |
ng update |
|
identify dependencies to update |
ng add |
|
add libraries like Material |
Common Flags
COMMAND |
FLAG |
ALIAS |
DESCRIPTION |
All |
--help |
|
list flags (new/s/g) |
All |
--dry-run |
-d |
show potential file changes |
New |
--skip-tests |
-S |
no spec files |
New |
--skip-install |
|
don't install dependencies |
New |
--prefix |
-p ng |
prefix for all selectors |
New |
--skip-git |
-g |
don't add git |
New |
--style scss |
|
set up using SASS |
New |
--routing |
|
generates routing module |
Serve |
-prod |
|
run from production |
Serve |
-open |
-o |
opens in browser |
Notes
Certain Blueprints (components/modules) create a folder - unless a folder has already been created. Use the --flat flag to prevent a folder from being created. Service & Interface do not create folders.
Remember to consider where components should reside. You may want to add a login component inside an account module. This would be done by first creating the module ng g m account --routing then adding the login component inside account and importing it the correct module ng g c account/login -m=account. |
Yarn vs NPM
Enable Yarn |
ng config -g cli.packageManager yarn |
Enable NPM |
ng config -g cli.packageManager npm |
|
|
ng update
|
update core/rxJS/TScript |
ng update @angular/material
|
update Material |
ng add - Schematics
|
app manifest + service worker |
ng add @ng-bootstrap/schematics
|
|
ng add @angular/material
|
|
ng add @clr/angular@next
|
|
|
Material Schematics |
ng g @angular/material:material-nav --name=nav
|
Nav Menu |
ng g @angular/material:material-dashboard --name=dash
|
Cards |
ng g @angular/material:material-table --name=table
|
Table |
Makes it easy to add and update 3rd party libraries.
Blueprints
component |
c |
service |
s |
pipe |
p |
interface |
i |
module |
m |
class |
class |
--flat |
|
don't create a folder |
--spec false |
-S |
no spec files |
--inline-style |
-s |
no CSS files |
--inline-template |
-t |
no HTML files |
--skip-import |
|
don't add to module |
--dry-run |
-d |
report files, don't write |
-m |
-m |
specify which module to import into |
Blueprints - The concept angular uses to generate code.
Blueprint Examples
|
create account Module along w/ folder |
ng g c account/login -m account
|
new login Component added to account module |
ng g s account/login -m account
|
new login Service added to account module |
|
new person Interface added to models |
ng new myApp -S -g --routing
|
new project no spec or git w/ routing |
|