Sub topic 1
What Angular DevTools Does and Where It Fits
Prerequisites
This chapter assumes you know basic Angular components, templates, services, and TypeScript. You should also know how to open browser developer tools and have an Angular application running in development mode.
What Angular DevTools Does
Angular DevTools is a browser extension for examining a running Angular application. It adds panels to the browser’s developer tools. These panels show the component tree, component state, dependency-injection relationships, router information, and change-detection performance.
Use it when the page behaves differently from what you expect. For example, you can find which component owns a value, inspect an input passed by a parent, or identify components that take too long during change detection. DevTools complements the Elements, Console, and Network panels. It does not replace them.
Installing the Extension and Meeting Its Requirements
Install Angular DevTools from the extension store for a supported Chromium-based browser or Firefox. Start your application with the Angular development server, commonly with ng serve, and open it in that browser.
Angular DevTools needs Angular’s development-mode debugging information. It usually will not attach to a production build because production builds remove or disable these debugging hooks.
When the extension detects the application, open browser developer tools and select the Angular tab. If the tab is missing, confirm that the page contains Angular, the browser supports the extension, and the application is not running as a production build.
Exploring the Component Tree
The component explorer presents Angular’s rendered hierarchy. Select a component in the tree to inspect it. The selected component corresponds to part of the page, which helps connect visible elements to Angular source code.
A simplified relationship looks like this:
Large trees can contain repeated components. Select the instance associated with the problem rather than assuming every component with the same class has the same state.
Inspecting Properties, Inputs, and Outputs
The inspector shows properties on the selected component and identifies values supplied through inputs. An input is data received from a parent component. An output is an event emitter or other event mechanism that lets a child notify its parent.
Inspect these values at the moment the UI is wrong. Compare the child’s inputs with the parent’s state. Then inspect outputs to see whether the expected event exists and whether its value matches the event handler’s expectation.
Exercise
Why might Angular DevTools fail to show its panel for an application?
Show answer
The application may be a production build, the browser may be unsupported, or the page may not contain an Angular application.