Effective Angular

Book description

Develop your front-end expertise and build scalable, enterprise-ready web applications by efficiently using the Angular framework's powerful features and essential libraries

Key Features

  • Implement design patterns and Nx for optimal maintainability and scalability of your code base
  • Explore reactive programming and state management using RxJS, Signals, and NgRx
  • Build and test large-scale Angular monorepo applications using Nx, Jest, and Cypress
  • Purchase of the print or Kindle book includes a free PDF eBook

Book Description

Angular is an open-source, front-end framework used to build web applications using TypeScript. Angular is a component-based framework, which means you build apps by developing and composing reusable components. This framework has all the built-in features needed to develop complex, feature-rich web apps. Written by an Angular specialist working with some of the top companies in the Netherlands, this book teaches you how to harness the full potential of the Angular framework.

You’ll explore different front-end architecture designs and set up a scalable environment for Angular applications and libraries using Nx, before taking a deep dive into the framework's newest and most powerful features. Next, you’ll learn to manipulate the Document Object Model (DOM) with Angular directives, pipes, and animations, and build reusable components like a pro. The book spotlights best practices and flags potential pitfalls at every step of the way. You’ll also learn design patterns that fit well when using the Angular framework, reactive programming with RxJS and Angular signals, and how to manage application states effectively. The book teaches you about accessibility, testing, and optimizing your app for deployment.

By the end of this book, you’ll be able to use Angular effectively to build enterprise-ready, scalable front-end applications.

What you will learn

  • Create Nx monorepos ready to handle hundreds of Angular applications
  • Reduce complexity in Angular with the standalone API, inject function, control flow, and Signals
  • Effectively manage application state using Signals, RxJS, and NgRx
  • Build dynamic components with projection, TemplateRef, and defer blocks
  • Perform end-to-end and unit testing in Angular with Cypress and Jest
  • Optimize Angular performance, prevent bad practices, and automate deployments

Who this book is for

If you are a front-end engineer ready to level up your Angular skills, then this book is for you. This book will help you learn how to build applications of any scale by utilizing the powerful features of the Angular framework. Basic knowledge of the Angular framework will enable you to grasp the concepts explained in this book, including the newest Angular features such as standalone components, Signals, control flow, front-end architecture, building Angular monorepo applications using Nx, reactive programming with RxJS, and managing application state with NgRx.

Table of contents

  1. Effective Angular
  2. Contributors
  3. About the author
  4. About the reviewers
  5. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
    4. Download the example code files
    5. Conventions used
    6. Get in touch
    7. Share Your Thoughts
    8. Download a free PDF copy of this book
  6. Part 1:Angular Basics and Setting Up Scalable Nx Workspaces
  7. Chapter 1: Scalable Front-End Architecture for Angular Applications
    1. Technical requirements
    2. Understanding scalable front-end applications
      1. What is scalability?
      2. Why is front-end architecture important?
    3. Different approaches to scaling front-end applications
      1. Monorepo or polyrepo
      2. Architectural patterns for Angular applications
      3. Design patterns used within Angular applications
    4. What is Nx and why should you use it?
      1. How Nx helps you build Angular monorepos that scale
    5. Setting up a scalable Angular workspace
      1. What did Nx create in our new workspace?
      2. Improving our Nx workspace for better Angular development
      3. Structuring Angular applications and libraries
      4. Do you create a new library or reuse an existing one?
    6. Summary
  8. Chapter 2: Powerful Angular Features
    1. What makes Angular so powerful?
    2. New features in the Angular framework
      1. Standalone components
      2. Dependency injection using the inject function
      3. Directive composition
      4. Angular Signals
      5. Angular control flow
      6. Other noteworthy new Angular features
    3. A deep dive into Angular routing
      1. Creating new components
      2. Configuring routes in Angular applications
      3. Route configuration options
    4. Component communication
      1. Receiving values with the @input() decorator
      2. Emitting values with the @Output() decorator
      3. Two-way data binding using @Input and @Output
      4. Other component communication methods
    5. Dependency injection
      1. Providing dependencies
      2. Injecting dependencies
      3. Using the inject function for better dependency injection
      4. Dependency instances, injector hierarchy, and resolution modifiers
    6. Summary
  9. Chapter 3: Enhancing Your Applications with Directives, Pipes, and Animations
    1. Using and creating Angular directives
      1. Angular attribute directives
      2. Angular structural directives
      3. Directive selectors
      4. Angular directive composition
    2. Transforming values using Angular pipes
      1. Using pipes in HTML templates and TypeScript files
      2. Is it pure or impure?
      3. Using AsyncPipe
      4. Building your own pipes
    3. Creating and reusing stunning animations
    4. Summary
  10. Chapter 4: Building Forms Like a Pro
    1. Understanding the different types of forms in Angular
    2. Building template-driven forms
      1. Creating a forms library with a form component
      2. Creating a template-driven form
    3. Building reactive forms
      1. Creating a reactive form
    4. Creating forms dynamically
    5. Summary
  11. Part 2:Handling Application State and Writing Cleaner, More Scalable Code
  12. Chapter 5: Creating Dynamic Angular Components
    1. A deep dive into Angular content projection
      1. Creating a modal component using content projection
      2. Exploring multi-slot content projection with ng-content select
      3. Displaying projected content multiple times or conditionally
    2. Using template references and variables
      1. Using template variables effectively
      2. Using TemplateRef elements effectively
    3. Rendering components dynamically
      1. Rendering components dynamically using ngComponentOutlet
      2. Using an injector with ngComponentOutlet
      3. Lazy loading dynamic components
      4. Rendering components dynamically using the defer control flow
    4. Summary
  13. Chapter 6: Applying Code Conventions and Design Patterns in Angular
    1. Exploring commonly used code conventions and best practices in Angular applications
      1. Naming conventions
      2. Structural conventions
      3. Using best practices in Angular applications
    2. Exploring commonly used design patterns in Angular applications
      1. Creational design patterns in Angular
      2. Structural design patterns in Angular
      3. Behavioral design patterns in Angular
    3. Building a generic HTTP service containing a model adapter
      1. Using the generic HTTP service
      2. Providing mock data for our API requests
    4. Summary
  14. Chapter 7: Mastering Reactive Programming in Angular
    1. What is reactive programming?
      1. Highlights of reactive programming
      2. Drawbacks of reactive programming
    2. Reactive programming in Angular
    3. Reactive programming using RxJS
      1. What are Observables?
      2. Unsubscribing from Observables
      3. Using and creating RxJS operators
      4. Types of operators
      5. Flattening multiple Observable streams using flattening operators
      6. Powerful and useful RxJS operators
      7. Creating combined and reusable RxJS operators
    4. Reactive programming using Angular Signals
      1. Using Signals, computed Signals, and Signals effects
    5. Combining Signals and RxJS
      1. Using toSignal
      2. Using toObservable
      3. Choosing between Signals and RxJS
    6. Summary
  15. Chapter 8: Handling Application State with Grace
    1. Understanding application state
      1. Different levels of application state
      2. Fundamental concepts within state management
    2. Handling global application state using RxJS
      1. Building a state management solution using RxJS
      2. Connecting your state management and view layer with a facade service
    3. Handling global application state using Signals
    4. The problem with using RxJS or Signals for global state management
    5. Handling global application state with NgRx
      1. Installing the @ngrx/store and @ngrx/effects packages
      2. Defining your first NgRx actions
      3. Creating your first NgRx effect
      4. Creating your initial state and first reducer functions
      5. Defining NgRx selectors
      6. Adjusting the facade service so that they use NgRx state management
      7. Adding additional actions, effects, reducers, and selectors
    6. Summary
  16. Part 3:Getting Ready for Production with Automated Tests, Performance, Security, and Accessibility
  17. Chapter 9: Enhancing the Performance and Security of Angular Applications
    1. Understanding Angular change detection
      1. Zone.js and Angular
      2. Improving change detection efficiency
      3. Angular change detection and Signals
    2. Enhancing the performance of Angular applications
      1. Understanding and using the runOutsideAngular() method
      2. Understanding and using the NgOptimizedImage directive
      3. Understanding and using the trackBy and track functions
      4. Understanding and using web workers in Angular
    3. Building secure Angular applications
      1. Setting up route guards
      2. Angular attack surfaces and how to mitigate them
    4. Summary
  18. Chapter 10: Internationalization, Localization, and Accessibility of Angular Applications
    1. Adding translatable content in Angular applications
      1. Installing Transloco in your Nx monorepo
      2. Translating content using Transloco
      3. Changing the Transloco configurations at runtime
    2. Localization for Angular applications
      1. Localizing currencies using the translocoCurrency pipe
      2. Localizing dates using the translocoDate pipe
      3. Localizing numbers using the translocoDecimal pipe
    3. Making your Angular applications accessible to everyone
      1. How to make Angular applications accessible
      2. Using the tabindex attribute
      3. Adding ARIA attributes
    4. Summary
  19. Chapter 11: Testing Angular Applications
    1. Different types of application testing
      1. Understanding unit tests
      2. Understanding end-to-end tests
      3. Understanding component tests
      4. Understanding integration tests
    2. Unit testing of Angular applications using Jest
      1. Setting the coverage threshold
      2. Adding additional configurations
      3. Writing and running unit tests
      4. Adding additional unit tests for the expenses-registration application
    3. End-to-end testing of Angular applications using Cypress
      1. Writing your first e2e test
      2. Defining page objects for e2e testing
      3. Using fixtures in your e2e tests
    4. Summary
  20. Chapter 12: Deploying Angular Applications
    1. Building and linting Angular applications inside your Nx monorepo
      1. Linting Nx projects
      2. Building your Angular libraries and applications
    2. Analyzing your build output
    3. Automatically deploying Angular applications
      1. Creating an access token
      2. Creating a .yml file
      3. Deploying the application to GitHub Pages
      4. Fixing workflow fails
    4. Summary
  21. Index
    1. Why subscribe?
  22. Other Books You May Enjoy
    1. Packt is searching for authors like you
    2. Share Your Thoughts
    3. Download a free PDF copy of this book

Product information

  • Title: Effective Angular
  • Author(s): Roberto Heckers
  • Release date: August 2024
  • Publisher(s): Packt Publishing
  • ISBN: 9781805125532