Learning Angular [4 ed.] 9781803240602

458 265 8MB

English Pages 447 Year 2023

Report DMCA / Copyright

DOWNLOAD FILE

Learning Angular [4 ed.]
 9781803240602

Table of contents :
Cover
Copyright
Table of Contents
Preface
Chapter 1: Building Your First Angular Application
Technical requirements
What is Angular?
Why choose Angular?
Cross-platform
Tooling
Onboarding
Who uses Angular?
Setting up the Angular CLI workspace
Prerequisites
Node.js
npm
Git
Installing the Angular CLI
CLI commands
Creating a new project
Structure of an Angular application
Components
Modules
Template syntax
VS Code tooling
Angular Language Service
Angular Snippets
Nx Console
Material icon theme
EditorConfig
Angular Evergreen
Rename Angular Component
Summary
Chapter 2: Introduction to TypeScript
The history of TypeScript
The benefits of TypeScript
Introducing TypeScript resources
The official website
The official wiki documentation
Types
String
Declaring variables
The let keyword
The const keyword
Number
Boolean
Array
Dynamic typing with no type
Custom types
Enum
Void
Type inference
Functions, lambdas, and execution flow
Annotating types in functions
Function parameters in TypeScript
Optional parameters
Default parameters
Rest parameters
Function overloading
Arrow functions
Common TypeScript features
Spread parameter
Template strings
Generics
Optional chaining
Nullish coalescing
Classes, interfaces, and inheritance
Anatomy of a class
Constructor parameters with accessors
Interfaces
Class inheritance
Decorators
Class decorators
Extending a class decorator
Property decorators
Method decorators
Parameter decorator
Advanced types
Partial
Record
Union
Modules
Summary
Chapter 3: Organizing Application into Modules
Technical requirements
Introducing Angular modules
Creating our first module
Group application features into modules
Add a module in the main module
Exposing feature modules
Organizing modules by type
Leveraging Angular built-in modules
Summary
Chapter 4: Enabling User Experience with Components
Technical requirements
Creating our first component
The structure of an Angular component
Registering components with modules
Creating standalone components
Interacting with the template
Loading the component template
Displaying data from the component class
Styling the component
Getting data from the template
Component inter-communication
Passing data using an input binding
Listening for events using an output binding
Emitting data through custom events
Local reference variables in templates
Encapsulating CSS styling
Deciding on a change detection strategy
Introducing the component lifecycle
Performing component initialization
Cleaning up component resources
Detecting input binding changes
Accessing child components
Summary
Chapter 5: Enrich Applications Using Pipes and Directives
Technical requirements
Introducing directives
Transforming elements using directives
Displaying data conditionally
Iterating through data
Switching through templates
Manipulating data with pipes
Building custom pipes
Sorting data using pipes
Change detection with pipes
Creating standalone pipes
Building custom directives
Displaying dynamic data
Property binding and responding to events
Creating components dynamically
Toggling templates dynamically
Creating standalone directives
Summary
Chapter 6: Managing Complex Tasks with Services
Technical requirements
Introducing Angular DI
Creating our first Angular service
Providing dependencies across the application
Injecting services in the component tree
Sharing dependencies through components
Root and component injectors
Sandboxing components with multiple instances
Restricting DI down the component tree
Restricting provider lookup
Overriding providers in the injector hierarchy
Overriding service implementation
Providing services conditionally
Transforming objects in Angular services
Summary
Chapter 7: Being Reactive Using Observables and RxJS
Technical requirements
Strategies for handling asynchronous information
Shifting from callback hell to promises
Observables in a nutshell
Reactive programming in Angular
The RxJS library
Creating observables
Transforming observables
Higher-order observables
Subscribing to observables
Unsubscribing from observables
Destroying a component
Using the async pipe
Summary
Chapter 8: Communicating with Data Services over HTTP
Technical requirements
Communicating data over HTTP
Introducing the Angular HTTP client
Setting up a backend API
Handling CRUD data in Angular
Fetching data through HTTP
Modifying data through HTTP
Adding new products
Updating product price
Removing a product
Authentication and authorization with HTTP
Authenticating with backend API
Authorizing user access
Authorizing HTTP requests
Summary
Chapter 9: Navigating through Application with Routing
Technical requirements
Introducing the Angular router
Specifying a base path
Importing the router module
Configuring the router
Rendering components
Creating an Angular application with routing
Scaffolding an Angular application with routing
Configuring routing in our application
Creating feature routing modules
Handling unknown route paths
Setting a default path
Navigating imperatively to a route
Decorating router links with styling
Passing parameters to routes
Building a detail page using route parameters
Reusing components using child routes
Taking a snapshot of route parameters
Filtering data using query parameters
Enhancing navigation with advanced features
Controlling route access
Preventing navigation away from a route
Prefetching route data
Lazy-loading routes
Protecting a lazy-loaded module
Lazy loading components
Summary
Chapter 10: Collecting User Data with Forms
Technical requirements
Introducing forms to web apps
Data binding with template-driven forms
Using reactive patterns in Angular forms
Interacting with reactive forms
Providing form status feedback
Creating nesting form hierarchies
Creating elegant reactive forms
Validating controls in a reactive way
Building a custom validator
Modifying forms dynamically
Manipulating form data
Watching state changes and being reactive
Summary
Chapter 11: Introduction to Angular Material
Technical requirements
Introducing Material Design
Introducing Angular Material
Adding Angular Material to your application
Adding Angular Material controls
Theming Angular Material components
Adding core UI controls
Buttons
Form controls
Input
Autocomplete
Select
Checkbox
Date picker
Navigation
Layout
List
Grid list
Popups and modal dialogs
Creating a simple dialog
Configuring a dialog
Getting data back from a dialog
Data table
Table
Sort table
Pagination
Integration controls
Introducing the Angular CDK
Clipboard
Drag and drop
Summary
Chapter 12: Unit Test an Angular Application
Technical requirements
Why do we need tests?
The anatomy of a unit test
Introducing unit tests in Angular
Testing components
Testing with dependencies
Replacing the dependency with a stub
Spying on the dependency method
Testing asynchronous services
Testing with inputs and outputs
Testing with a component harness
Testing services
Testing a synchronous method
Testing an asynchronous method
Testing services with dependencies
Testing pipes
Testing directives
Testing forms
Summary
Chapter 13: Bringing an Application to Production
Technical requirements
Building an Angular application
Building for different environments
Building for the window object
Limiting the application bundle size
Optimizing the application bundle
Deploying an Angular application
Summary
Chapter 14: Handling Errors and Application Debugging
Technical requirements
Handling application errors
Catching HTTP request errors
Creating a global error handler
Responding to 401 Unauthorized error
Demystifying framework errors
Debugging Angular applications
Using the Console API
Adding breakpoints in source code
Using Angular DevTools
Summary
Packt page
Other Books You May Enjoy
Index

Polecaj historie