Angular Workshop
Part I. Fundamentals
CARLOS CABALLERO
PHD COMPUTER SCIENCE�VOCATIONAL TRAINING TEACHER
NPKILL
ANGULAR MÁLAGA
ANGULAR COMMUNITIES
@DotTechES
Table of Contents
What is Angular?
Standalone-Components
Communication between components (@Input/@Output)
Reactive Forms
Services
Router: Pages/Components
Communication between backend and frontend (Http)
Organizing Project: Features Modules/Pages/Components
Login/Register Pages/Components
Guards
Interceptors
Angular Workshop Part II - State Management: NgRX
Link to the repository
Encuesta Angular
Angular is a development platform, built on TypeScript. As a platform, Angular includes:
What is Angular?
Single Page Application (SPA)
Angular CLI
8
npm install -g @angular/cli
Angular – Standalone Code Structure
ng new workshop-fundamentals --standalone
This command will create a new directory with the boilerplate project and install all required dependencies – thousands of files in the node_modules directory of your project
Key files:
Project dependencies
Top-level components
App bootstrap
Root configuration
Angular – How does it work
10
Angular Building Blocks
Standalone Component
Standalone Components (01-single-component)
Angular - Standalone Components
Angular – Create New Component
ng g component components/hero-item
Angular – Component Details
Component Class
Metadata
hero-item.component.ts
Component decorator
Imports Modules and Standalone Components
Template
Styles
Angular HeroItem – Component Class
Angular HeroItem – Template
Angular HeroItem – Load component
app.component.ts
app.component.html
Angular – Standalone Component
ng serve
Angular - Standalone Components
Angular HeroItem – *ngFor | pipe
Angular - Standalone Components
Communication between Components (@Input/@Output)
Communication between components (02-communication)
Angular – @Input/@Output
Angular – @Input/@Output
27
ng g component components/hero-list
Angular - Communication Between Components (@Input/@Output)
Reactive Forms
Reactive Forms (03.01-form-new)
Angular – Reactive and Template-Driven Forms
| REACTIVE | TEMPLATE-DRIVEN |
Setup of form model | Explicit, created in component class | Implicit, created by directives |
Data model | Structured and immutable | Unstructured and mutable |
Data flow | Synchronous | Asynchronous |
Form validation | Functions | Directives |
Angular – Reactive and Template-Driven Forms
BASE CLASSES | DETAILS |
FormControl | Tracks the value and validation status of an individual form control |
FormGroup | Tracks the same values and status for a collection of form control |
FormArray | Tracks the same values ad status for an array of form controls |
ControlValueAccessor | Creates a bridge between Angular FormControl instances and built-in DOM elements |
Angular – Reactive Forms
Angular – Reactive Forms - FormBuilder
Angular - Reactive Forms
Angular – Form Control States (03.02-form-new-error)
Angular – Form Control States
STATE | DETAILS | CSS-Class |
Pristine | The user has not modified the form control | .ng-pristine |
Dirty | The user has modified the form control | .ng-dirty |
Touched | The user has interacted with the form control, e.g., by clicking or focusing on it. | .ng-touched |
Untouched | The form control has not been interacted with by the user | .ng-untouched |
Valid | The form control’s value meets the validation rules defined in the application | .ng-valid |
Invalid | The form control’s value does not meet the validation rules defined in the application | .ng-invalid |
Angular – Form Control States
Angular – Form Control States
Angular – Form Control States
Services
Angular – Services (04.01-services)
Angular – Create Service
ng g service shared/services/hero
Angular – Service Details
@Injectable() decorator to provide the metadata that allows Angular to inject it into a component as a dependency
The hero service is injected
into the App component
Angular – Services
Router
Angular – Router (05.01-router)
Angular – Router
Angular – Router
Angular – Router
Each route has 2 properties:
Angular – Router
Each route has 2 properties:
Angular - Router
Angular – Router (05.02-router-params)
Angular – Router
Each route has 2 properties:
Angular – Router
Each route has 2 properties:
Angular - Router Params
Communication between client and backend (Http)
Angular – HTTP (06.01-http)
Angular - HTTP
Angular - Http - Observables
Angular - Http - Observables
Component (Observer)
Component (Observer)
Service (Observable)
Back-end
e-store (in-memory)
e-store (store on disk)
HTTP Requests
Response
Routing
Angular - Http - Observables
Observable object
Using Chrome’s developer tools, we can see our message logged to the console when the button is clicked
Angular - Http - Observables
values, but it is not executed until an observer (consumer) subscribes to it
Observable (publisher)
Observer (consumer)
[data]
[data]
[data]
subscribes
Angular - HTTP - Observables
Observable (publisher)
Observer (consumer)
subscribe
next
error
complete
listen
Angular - Http - Observables
Angular - HTTP
THANK YOU!
Link to the channel
Carlos Caballero
@Caballerog
@carlillo