Sub topic 2
Editing Runtime State and Profiling Change Detection
Assume you know Angular components, templates, TypeScript, and browser developer tools. Keep an Angular application running in development mode with Angular DevTools installed.
Editing Values at Runtime and Viewing Source
Open Angular DevTools and select the Components panel. Choose a component in the tree. Its properties, inputs, and outputs appear in the details pane.
Edit a displayed property to test a UI state without changing the source file. For example, change a component's title from Dashboard to Loading failed. Angular updates the view when the value is applied. This helps reproduce states that are difficult to reach through normal user actions.
Runtime edits are temporary. Refreshing the page usually removes them. Use the source link or the component's location information to jump from the inspected instance to the relevant source file. Make the permanent change there only after you understand the behavior.
export class ReportComponent {
title = 'Daily report';
showWarning = false;
}A useful test is to edit showWarning to true, inspect the resulting view, and then edit it back. Check whether child components receive the expected input values.
Change Detection: The Background You Need for Profiling
Change detection is Angular's process for checking template bindings and updating the DOM when application state may have changed. A change detection pass can run after events, timer callbacks, HTTP results, or other application activity.
A component can become slow when its template performs expensive work during every pass. A method called from a template may run many times, even when the displayed data has not changed.
export class ReportComponent {
rows = [{ name: 'A', values: [2, 3, 4] }];
total(values: number[]): number {
return values.reduce((sum, value) => sum + value, 0);
}
}Recording a Profiler Session
Open the Profiler panel and start recording. Perform one focused action, such as typing in a filter or clicking a button. Stop the recording after the behavior occurs.
Avoid recording page startup unless startup performance is your target. A short, repeatable interaction makes the result easier to interpret.
Reading Change Detection Results
Angular DevTools displays change detection cycles and the components involved in them. Look for components with high total time, many checks, or long individual work.
Select a slow cycle to inspect its component details. Compare recordings after each code change. A component that appears in many cycles may be receiving frequent updates, while a component with one long duration may contain costly template work.
Exercise
Why should a profiling recording contain one focused interaction?
Show answer
It makes the resulting cycles and component timings easier to connect to the behavior being investigated.