Sub topic 5
Editing values at runtime and viewing source
This chapter assumes you can already open Angular DevTools, select a component in the component tree, and read its properties, inputs, and outputs. You should also know basic TypeScript and have an Angular app running in development mode. Here you will change state from the panel, reproduce UI states, and jump from a component to its code.
Why edit state at runtime
Many bugs only show up in a particular state: an empty list, a long name, an error flag, a loading spinner. Reaching that state through the UI can take many clicks or a failing backend. DevTools lets you set the value directly and watch the template react. You test a hypothesis in seconds, without touching source code or restarting the dev server.
Edits are temporary. A page reload discards them, so nothing you change here reaches your project files.
Editing a property in the panel
- Open the Components tab and select a component in the tree.
- In the properties view on the right, find a primitive value such as a string, number, or boolean.
- Double-click the value, type a new one, and press Enter.
Angular DevTools writes the value to the component instance. For primitives, the view usually updates after a change detection pass. If it does not, the component may use OnPush or signals, which the next sections explain.
You can also expand objects and arrays and edit nested primitive values the same way. Editing a nested field is useful for testing how a template handles a long string or a negative number.
Why an edit sometimes does nothing visible
A value changes on the instance, but the screen may not follow. Common causes:
- The component uses
ChangeDetectionStrategy.OnPush, and no input reference changed, no event fired, and no signal was updated. Angular has no reason to check it. - The property is a signal or a computed value. A computed value is derived, so editing it does not make sense. Change the signal it reads from instead.
- The property is a getter. A getter has no stored value to overwrite.
When an edit is not reflected, treat that as information about how the component is wired, not as a DevTools fault.
Forcing a refresh from the console
The ng global is available in development mode. Select the element in the Elements panel, and the browser exposes it as $0. You can then change a property and ask Angular to re-render:
// In the browser console, after selecting an element in the Elements panel ($0):
const cmp = ng.getComponent($0);
console.log(cmp);
// Change a property, then ask Angular to re-render the component:
cmp.title = 'Changed from the console';
ng.applyChanges(cmp);ng.getComponent returns the component instance. ng.applyChanges runs change detection for that component, which is what makes an OnPush component show your edit. Later chapters cover the ng utilities in more detail.
Viewing source
Once you have found the component that misbehaves, you want its code. Selecting a component in the tree shows a </> icon beside its name in the properties panel. Clicking it opens the Sources panel of the browser at the component's class definition.
This works for directives too, and it saves you from searching the project by selector name. Two details matter:
- You see the code the browser loaded. With source maps enabled in development, that is your original TypeScript. Without source maps, it is compiled JavaScript.
- The link opens the class, not the template. If the template is inline, it appears in the
@Componentdecorator. If it lives in an HTML file, open that file separately.
Common mistakes
- Treating an edit as a fix. The change disappears on reload, so copy the working value into your source.
- Editing a derived value instead of its source signal.
- Testing in a production build. The
ngglobal and DevTools inspection need development mode.
Exercise
You edit a string property of an OnPush component in DevTools, but the template still shows the old text. Name one way to make the view update, and say why the edit alone was not enough.
Show answer
Select the element, get the instance with ng.getComponent($0), and call ng.applyChanges(cmp). The edit changed the instance, but an OnPush component is only checked when an input reference changes, an event fires, or a signal updates, so Angular did not re-render it until you triggered change detection.