Angular Cookbook

Book description

Discover actionable solutions to everyday problems in building applications with Angular and TypeScript, from app design to production deployment

Key Features

  • Explore recipes across core Angular topics to fill gaps in your knowledge of using Angular in production
  • Discover industry best practices and tooling to enhance your development experience with Angular
  • Understand advanced topics in Angular to help you become a proficient enterprise web developer

Book Description

The Angular framework, powered by Google, is the framework of choice for many web development projects built across varying scales. It’s known to provide much-needed stability and a rich tooling ecosystem for building production-ready web and mobile apps. This recipe-based guide enables you to learn Angular concepts in depth using a step-by-step approach. You’ll explore a wide range of recipes across key tasks in web development that will help you build high-performance apps.

The book starts by taking you through core Angular concepts such as Angular components, directives, and services to get you ready for building frontend web apps. You’ll develop web components with Angular and go on to cover advanced concepts such as dynamic components loading and state management with NgRx for achieving real-time performance. Later chapters will focus on recipes for effectively testing your Angular apps to make them fail-safe, before progressing to techniques for optimizing your app’s performance. Finally, you’ll create Progressive Web Apps (PWA) with Angular to provide an intuitive experience for users.

By the end of this Angular book, you’ll be able to create full-fledged, professional-looking Angular apps and have the skills you need for frontend development, which are crucial for an enterprise Angular developer.

What you will learn

  • Gain a better understanding of how components, services, and directives work in Angular
  • Understand how to create Progressive Web Apps using Angular from scratch
  • Build rich animations and add them to your Angular apps
  • Manage your app’s data reactivity using RxJS
  • Implement state management for your Angular apps with NgRx
  • Optimize the performance of your new and existing web apps
  • Write fail-safe unit tests and end-to-end tests for your web apps using Jest and Cypress
  • Get familiar with Angular CDK components for designing effective Angular components

Who this book is for

The book is for intermediate-level Angular web developers looking for actionable solutions to common problems in Angular enterprise development. Mobile developers using Angular technologies will also find this book useful. Working experience with JavaScript and TypeScript is necessary to understand the topics covered in this book more effectively.

Table of contents

  1. Angular Cookbook
  2. Foreword
  3. Contributors
  4. About the author
  5. About the reviewer
  6. 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. Download the color images
    6. Conventions used
    7. Get in touch
    8. Share Your Thoughts
  7. Chapter 1: Winning Components Communication
    1. Technical requirements
    2. Components communication using component @Input(s) and @Output(s)
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. See also
    3. Components communication using services
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. See also
    4. Using setters for intercepting input property changes
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. See also
    5. Using ngOnChanges to intercept input property changes
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. See also
    6. Accessing a child component in the parent template via template variables
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. See also
    7. Accessing a child component in a parent component class using ViewChild
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. See also
    8. Creating your first dynamic component in Angular
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. See also
  8. Chapter 2: Understanding and Using Angular Directives
    1. Technical requirements
    2. Using attribute directives to handle the appearance of elements
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. See also
    3. Creating a directive to calculate the read time for articles
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. See also
    4. Creating a basic directive that allows you to vertically scroll to an element
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. There's more…
    5. Writing your first custom structural directive
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. See also
    6. How to use *ngIf and *ngSwitch together
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. See also
    7. Enhancing template type checking for your custom directives
      1. Getting ready
      2. How to do it…
      3. See also
  9. Chapter 3: The Magic of Dependency Injection in Angular
    1. Technical requirements
    2. Configuring an injector with a DI token
      1. Getting ready
      2. How to do it...
      3. How it works
      4. See also
    3. Optional dependencies
      1. Getting ready
      2. How to do it
      3. How it works
      4. See also
    4. Creating a singleton service using providedIn
      1. Getting ready
      2. How to do it
      3. How it works
      4. See also
    5. Creating a singleton service using forRoot()
      1. Getting ready
      2. How to do it
      3. How it works
      4. See also
    6. Providing different services to the app with the same Aliased class provider
      1. Getting ready
      2. How to do it
      3. How it works
      4. See also
    7. Value providers in Angular
      1. Getting ready
      2. How to do it
      3. How it works
      4. See also
  10. Chapter 4: Understanding Angular Animations
    1. Technical requirements
    2. Creating your first two-state Angular animation
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. There's more…
      5. See also
    3. Working with multi-state animations
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. See also
    4. Creating complex Angular animations using keyframes
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. See also
    5. Animating lists in Angular using stagger animations
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. See also
    6. Using animation callbacks
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. See also
    7. Basic route animations in Angular
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. See also
    8. Complex route animations in Angular using keyframes
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. See also
  11. Chapter 5: Angular and RxJS – Awesomeness Combined
    1. Technical requirements
    2. Working with RxJS operators using instance methods
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. See also
    3. Working with RxJS operators using static methods
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. See also
    4. Unsubscribing streams to avoid memory leaks
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. There's more…
      5. See also
    5. Using an Observable with the async pipe to synchronously bind data to your Angular templates
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. See also
    6. Using combineLatest to subscribe to multiple streams together
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. See also
    7. Using the flatMap operator to create sequential HTTP calls
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. See also
    8. Using the switchMap operator to switch the last subscription with a new one
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. See also
    9. Debouncing HTTP requests using RxJS
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. See also
  12. Chapter 6: Reactive State Management with NgRx
    1. Technical requirements
    2. Creating your first NgRx store with actions and reducer
      1. Getting ready
      2. How to do it…
      3. See also
    3. Using @ngrx/store-devtools to debug the state changes
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. There's more…
      5. See also
    4. Creating an effect to fetch third-party API data
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. See also
    5. Using selectors to fetch data from stores in multiple components
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. See also
    6. Using @ngrx/component-store for local state management within a component
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. See also
    7. Using @ngrx/router-store to work with route changes reactively
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. See also
  13. Chapter 7: Understanding Angular Navigation and Routing
    1. Technical requirements
    2. Creating an Angular app with routes using the CLI
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. See also
    3. Feature modules and lazily loaded routes
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. See also
    4. Authorized access to routes using route guards
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. See also
    5. Working with route parameters
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. See also
    6. Showing a global loader between route changes
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. See also
    7. Preloading route strategies
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. See also
  14. Chapter 8: Mastering Angular Forms
    1. Technical requirements
    2. Creating your first template-driven Angular form
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. See also
    3. Form validation with template-driven forms
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. See also
    4. Testing template-driven forms
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. See also
    5. Creating your first Reactive form
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. See also
    6. Form validation with Reactive forms
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. See also
    7. Creating an asynchronous validator function
      1. Getting ready
      2. How it works…
      3. See also
    8. Testing Reactive forms
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. See also
    9. Using debounce with Reactive form control
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. See also
    10. Writing your own custom form control using ControlValueAccessor
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. See also
  15. Chapter 9: Angular and the Angular CDK
    1. Technical requirements
    2. Using Virtual Scroll for huge lists
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. See also
    3. Keyboard navigation for lists
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. See also
    4. Pointy little popovers with the Overlay API
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. See also
    5. Using CDK Clipboard to work with the system clipboard
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. See also
    6. Using CDK Drag and Drop to move items from one list to another
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. See also
    7. Creating a multi-step game with the CDK Stepper API
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. See also
    8. Resizing text inputs with the CDK TextField API
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. See also
  16. Chapter 10: Writing Unit Tests in Angular with Jest
    1. Technical requirements
    2. Setting up unit tests in Angular with Jest
      1. Getting ready
      2. How to do it...
      3. See also
    3. Providing global mocks for Jest
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    4. Mocking services using stubs
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    5. Using spies on an injected service in a unit test
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    6. Mocking child components and directives using the ng-mocks package
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    7. Creating even easier component tests with Angular CDK component harnesses
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    8. Unit testing components with Observables
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
      5. Unit testing Angular Pipes
      6. Getting ready
      7. How to do it...
      8. See also
  17. Chapter 11: E2E Tests in Angular with Cypress
    1. Technical requirements
    2. Writing your first Cypress test
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. See also
    3. Validating if a DOM element is visible on the view
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. See also
    4. Testing form inputs and submission
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. See also
    5. Waiting for XHRs to finish
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. See also
    6. Using Cypress bundled packages
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. See also
    7. Using Cypress fixtures to provide mock data
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. See also
  18. Chapter 12: Performance Optimization in Angular
    1. Technical requirements
    2. Using OnPush change detection to prune component subtrees
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. See also
    3. Detaching the change detector from components
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. See also
    4. Running async events outside Angular with runOutsideAngular
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. See also
    5. Using trackBy for lists with *ngFor
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. See also
    6. Moving heavy computation to pure pipes
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. See also
    7. Using web workers for heavy computation
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. See also
    8. Using performance budgets for auditing
      1. Getting ready
      2. How to do it…
      3. See also
    9. Analyzing bundles with webpack-bundle-analyzer
      1. Getting ready
      2. How to do it…
      3. See also
  19. Chapter 13: Building PWAs with Angular
    1. Technical requirements
    2. Converting an existing Angular app into a PWA with the Angular CLI
      1. Getting ready
      2. How to do it
      3. How it works
      4. See also
    3. Modifying the theme color for your PWA
      1. Getting ready
      2. How to do it
      3. See also
    4. Using Dark Mode in your PWA
      1. Getting ready
      2. How to do it
      3. See also
    5. Providing a custom installable experience in your PWA
      1. Getting ready
      2. How to do it
      3. How it works
      4. See also
    6. Precaching requests using an Angular service worker
      1. Getting ready
      2. How to do it
      3. How it works
      4. See also
    7. Creating an App Shell for your PWA
      1. Getting ready
      2. How to do it
      3. How it works
      4. See also
    8. Why subscribe?
  20. Other Books You May Enjoy
    1. Packt is searching for authors like you
    2. Share Your Thoughts

Product information

  • Title: Angular Cookbook
  • Author(s): Muhammad Ahsan Ayaz
  • Release date: August 2021
  • Publisher(s): Packt Publishing
  • ISBN: 9781838989439