Book Image

Angular Cookbook

By : Muhammad Ahsan Ayaz
Book Image

Angular Cookbook

By: Muhammad Ahsan Ayaz

Overview of this book

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.
Table of Contents (15 chapters)

What this book covers

Chapter 1, Winning Components Communication, explains different techniques to use to implement communication between components in Angular. @Input() and @Output() decorators, services, and lifecycle hooks are covered as well. There is also a recipe for how to create a dynamic Angular component.

Chapter 2, Understanding and Using Angular Directives, gives an introduction to Angular directives and some recipes that use Angular directives, including attribute directives and structural directives.

Chapter 3, The Magic of Dependency Injection in Angular, includes recipes that cover optional dependencies, configuring an injection token, using the providedIn: 'root' metadata for Angular services, value providers, and aliased class providers.

Chapter 4, Understanding Angular Animations, contains recipes for implementing multi-state animations, staggering animations, keyframe animations, and animations for switching between routes in your Angular apps.

Chapter 5, Angular and RxJS – Awesomeness Combined, covers recipes on RxJS instance and static methods. It also has some recipes on the usage of the combineLatest, flatMap, and switchMap operators and covers some tips and tricks about using RxJS streams.

Chapter 6, Reactive State Management with NgRx, has recipes concerning the famous NgRX library and its core concepts. It covers core concepts such as NgRx actions, reducers, selectors, and effects and looks at using packages such as @ngrx/store-devtools and @component/store.

Chapter 7, Understanding Angular Navigation and Routing, explores recipes on lazily loaded routes, route guards, preloading route strategies, and some interesting techniques to be used with the Angular router.

Chapter 8, Mastering Angular Forms, covers recipes for template-driven forms, reactive forms, form validation, testing forms, and creating your own form control.

Chapter 9:, Angular and the Angular CDK, has a lot of cool Angular CDK recipes, including ones on virtual scroll, keyboard navigation, the overlay API, the clipboard API, CDK drag and drop, the CDK stepper API, and the CDK textfield API.

Chapter 10, Writing Unit Tests in Angular with Jest, covers recipes for unit testing with Jest, exploring global mocks in Jest, mocking services/child components/pipes, using Angular CDK component harnesses, and unit testing Observables.

Chapter 11, E2E Tests in Angular with Cypress, has recipes on E2E testing with Cypress in Angular apps. It covers validating forms, waiting for XHR calls, mocking HTTP call responses, using bundled packages with Cypress, and using fixtures in Cypress.

Chapter 12, Performance Optimizations in Angular, contains some cool techniques to improve an Angular app's performance by using the OnPush change detection strategy, lazily loading feature routes, detaching the change detector from a component, using web workers with Angular, using pure pipes, adding performance budgets to an Angular app, and using the webpack-bundle analyzer.

Chapter 13, Building PWAs with Angular, contains recipes to create a PWA with Angular. It covers specifying a theme color for the PWA, using a device's dark mode, providing a custom PWA install prompt, precaching requests using Angular's service worker, and using App Shell.