Learning Angular - Fourth Edition

Book description

Build your first production-grade web applications from scratch with Angular with the help of expert guidance and step-by-step explanations. Purchase of the print or Kindle book includes a free eBook in PDF format.

Key Features

  • Learn the fundamentals of Angular 15 to build web applications
  • Explore the basics of Angular development, from components and templates to forms, routing, and services
  • Discover best practices for building, deploying, debugging, and testing Angular applications

Book Description

As Angular continues to reign as one of the top JavaScript frameworks, more developers are seeking out the best way to get started with this extraordinarily flexible and secure framework. Learning Angular, now in its fourth edition, will show you how you can use it to achieve cross-platform high performance with the latest web techniques, extensive integration with modern web standards, and integrated development environments (IDEs).

The book is especially useful for those new to Angular and will help you to get to grips with the bare bones of the framework to start developing Angular apps. You'll learn how to develop apps by harnessing the power of the Angular command-line interface (CLI), write unit tests, style your apps by following the Material Design guidelines, and finally, deploy them to a hosting provider.

Updated for Angular 15, this new edition covers lots of new features and tutorials that address the current frontend web development challenges. You’ll find a new dedicated chapter on observables and RxJS, more on error handling and debugging in Angular, and new real-life examples.

By the end of this book, you’ll not only be able to create Angular applications with TypeScript from scratch, but also enhance your coding skills with best practices.

What you will learn

  • Use the Angular CLI to scaffold, build, and deploy a new Angular application
  • Build components, the basic building blocks of an Angular application
  • Discover new Angular Material components such as Google Maps, YouTube, and multi-select dropdowns
  • Understand the different types of templates supported by Angular
  • Create HTTP data services to access APIs and provide data to components
  • Learn how to build Angular apps without modules in Angular 15.x with standalone APIs
  • Improve your debugging and error handling skills during runtime and development

Who this book is for

This book is for JavaScript and full-stack developers dipping their feet first time in the world of frontend development with Angular, as well as those migrating to the Angular framework to build professional web applications. You'll need prior exposure JavaScript and a solid foundation in the basics of web programming before you get started with this book.

Table of contents

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

Product information

  • Title: Learning Angular - Fourth Edition
  • Author(s): Aristeidis Bampakos, Pablo Deeleman
  • Release date: February 2023
  • Publisher(s): Packt Publishing
  • ISBN: 9781803240602