ngModel, model(), and 2-way bindings in general

This week, we’re back to the 3-2-1 format of the newsletter. I’m posting a few essential articles to revisit, updates to know about, and one question to ponder:

Three articles to revisit:

Two quick updates:

One question to ponder:

What’s new in Angular 20.2?

Another month, another minor version of our favorite front-end framework!

Zoneless

This time around, Zoneless change detection becomes stable (more about Zoneless here), so you can remove Zone.js from the equation if you’ve followed the rules to make sure Angular will detect your changes properly with OnPush-compatible components.

Animations

The @angular/animations package is deprecated and replaced with a new API using the animate.enter/animate.leave syntax as follows:

 <div animate.enter="fade-in" animate.leave="fade-out">My content</div>Code language: HTML, XML (xml)

Aliases in blocks

You can use local aliases in if, else, and else if blocks as follows:


⁠@if (currentUser(); as user) {
  Welcome user {{ user.name }}!
} @else if (expiredSession(); as exp) {
  Please log in. Your session expired at {{ exp.time }}
}Code language: JavaScript (javascript)

New diagnostics

Diagnostics give you hints and feedback on possible mistakes. These apply to instances where your code compiles but is likely doing something wrong. A new diagnostic called uninvokedFunctionInTextInterpolation has been added to warn you when you use a method in a template without calling it (forgot the parentheses).

Testing

You can now use a headless browser with your Vitest unit tests using the builder introduced in v20. This is still experimental, though.

As a reminder, here are the updates from the previous version, Angular 20.1.

Visualizing internal dependencies with Madge

When working on large Angular projects, managing dependencies between files and modules can become a significant challenge. Madge is a developer tool that visualizes and analyzes module dependencies in JavaScript applications, making it an excellent companion for Angular developers.

Here is how to give it a try:

  1. Install madge: npm install -g madge
  2. In the root folder of your project, run: npx madge src/main.ts --ts-config tsconfig.json --image ./deps.png

This command will go through your entire application and create a dependency graph as an image in deps.png:

This can be used to identify circular dependencies, visualize relationships between your different components and services, and identify spaghetti code scenarios.

Note that Madge has other specific commands, such as one to detect circular dependencies:
npx madge --circular src/main.ts --ts-config tsconfig.json

Or that one to detect dead code (code that is never referred to anywhere in your app):

npx madge --orphans src/main.ts --ts-config tsconfig.json

You can find more information on Madge’s NPM page here.

Injection context, Angular talks, and more!

This week, we’re back to the 3-2-1 format of the newsletter. I’m posting a few essential articles to revisit, updates to know about, and one question to ponder:

Three (maybe four) articles to revisit:

  • Have you ever used ElementRef in Angular? It’s a way to access DOM elements natively, which can come in handy when integrating with some 3rd party libraries.
  • With the introduction of takeUntilDestroyed and the inject function, it has become more important than ever to understand what is an injection context.

Two quick updates:

  • A talk I’m looking forward to: The Angular team is presenting a “Deep Dive into the Angular Signal Forms” at Angular Connect on September 13th. Could it be a sign of imminent release in developer preview? Wait and see…

One question to ponder:

  • With Angular Signals now in the mix, many are rethinking their state management strategy. If you’re a long-time user of a state management library, has your perspective shifted? Knowing what you know now, would you still reach for a library on a new project?

Angular Newsletter Survey

It’s been quite some time since I last asked for feedback about the newsletter, and since we’re in the midst of summer and things tend to be a bit slower during that time of year, I thought now would be a good time to ask for your feedback.

Here is the feedback form for you, with just five quick questions and the option to provide more elaborate feedback if you wish. I’m always looking for external contributors, too, so feel free to let me know if you’d like to write about something interesting.

The regular newsletter will be back next week with a full article on the blog.

What’s new in Angular 20.1?

Angular 20.1 was just released by the Angular team, with a lot of good tools for improved developer experience:

Developer Tools

  • Signal Dependency Graphs: The Angular devtools extension includes an experimental feature to visualize the dependencies between signals in a graph. You can also inspect a signal and jump directly to its definition in the code. Signals also “blink” in the graph when their value changes.

Testing

  • Simplified Component Testing: New binding helpers (inputBinding(), outputBinding(), twoWayBinding()) allow you to set a component’s bindings directly during testing, without doing manual assignments or using wrapper components.

Performance

  • Optimized Template Compilation: The Angular compiler now uses more efficient, DOM-only instructions for elements that don’t have any directives applied, leading to better runtime performance.

Templates

  • Assignment Operators: You can now use assignment operators like +=, -=, and *= directly in your component templates.
  • NgOptimizedImage Decoding: The NgOptimizedImage directive now includes a decoding option, which can be set to async to avoid blocking the main JS thread.

HTTP Client

  • New HttpClient Options: A variety of new options have been added to HttpClient, including timeout, cache, priority, and credentials, giving you more control over HTTP requests and helping to improve Core Web Vitals.

AI and Angular CLI

  • AI-Assisted Development: Angular is integrating with AI development tools through the new ng mcp command, which starts a Model Control Protocol (MCP) server. This allows AI tools to better understand your Angular workspace for more accurate suggestions.
  • New Asset Loaders: The CLI now supports dataurl and base64 loaders, allowing you to inline small assets directly into your application’s code.

Angular Performance tools and suggestions

In the 3-2-1 format of the newsletter, I’m posting a few essential articles to revisit, updates to know about, and one question to ponder:

Three articles to revisit:

  • This series shows how simple template changes can impact performance: part 1part 2part 3.

Two quick updates:

  • Angular v20.1 is coming soon (the first RC is out) with new options and improvements for httpResource regarding authentication and caching.
  • The Angular team just posted more details about the new devtools track in Chrome, and it’s definitely a big improvement in terms of data integration, all in one place. The article features a few screenshots explaining the different colors used in the track, which seems well thought out and useful.

One question to ponder:

Do you use TypeScript path mapping to simplify your TS imports? If not, here’s what it does and how to enable it.

State Management, React, and Gemini

In the 3-2-1 format of the newsletter, I’m posting a few essential articles to revisit, updates to know about, and one question to ponder:

Three articles to revisit:

  • Even though Signals are changing the state management landscape in Angular, it’s still a good idea to know the basics of state management libraries to make an informed decision. Here are some past tutorials to learn about actions, reducerseffectsstate and store, or if you’d rather watch videos about it, I have this video course on LinkedIn Learning.

Two quick updates:

One question to ponder:

  • If you ever hear someone claiming that Angular is done, that everybody uses React these days, or any similar nonsense, here is a resource you can mention to such people:  https://www.madewithangular.com. That list is, of course, non-exhaustive, but the number of airlines and banks listed here should be plenty enough to silence doubters. And yes, Gemini, Google’s AI that beats ChatGPT in several areas, is made with Angular, too!

HTTP interceptors in Angular, using functions

In the past few years, Angular has started replacing some class-based features, such as guards and interceptors, with new function-based syntaxes.

What’s interesting about interceptors is that the old, dependency injection-based approach is not deprecated and remains valid, though it’s a bit more verbose and less convenient.

That said, I just updated this 2019 tutorial of mine to cover function-based interceptors instead:

The updated tutorial includes examples for intercepting both HTTP requests and responses.

Angular Profiling in Chrome’s Performance Dev Tools

Angular 20 introduced a new custom track in Google Chrome for extended information about events, change detection cycles, bindings, and more.

Here is what the track looks like – it can get toggled open or closed:

In the example above, we can see that a browser interaction triggered change detection in the AppComponent, which is pretty typical in a Zone.js-based Angular application.

The main benefit of the new track is that it ties together Angular-related information with regular browser information, such as memory usage and CPU usage, unlike the regular Angular DevTools extension, which gives Angular-specific information only.

To use the new track, ensure your project runs on Angular 20 in development mode. Then, open the browser developer tools, click on the “Performance” tab, and click the “Record” button (similar to the Angular DevTools profiler). Then, interact with the application and click “pause” when you want to stop the profiler and analyze the performance recording.

You can zoom in or out to focus on specific events of the recording and get detailed information about what happened at these different moments. This tool is perfect to detect useless change detection cycles that could be optimized by using the OnPush change detection strategy, for instance.

If you’re looking for more performance-related advice, my course “Angular Performance Optimization techniques” on LinkedIn Learning might be precisely what you’re looking for.