Open Menu

    Angular 19 Release Notes

    Flavio Del Grosso

    Flavio Del GrossoNov 21, 2024

    6 min read1506 words

    The release of Angular 19 marks a significant milestone in the evolution of the Angular framework. This new version introduces substantial improvements and features that enhance both the development experience and application performance. While maintaining a strong commitment to backward compatibility, Angular 19 brings forward at least one major change that developers need to be aware of—but rest assured, it's a change that is straightforward to manage.

    Standalone Components Become the Default

    Perhaps the most impactful change in Angular 19 is that standalone components, directives, and pipes are now the default setting when creating new elements in your application. This shift reflects a natural progression in Angular's architecture, emphasizing a more streamlined and efficient approach to building applications.

    The Journey to Standalone Defaults

    Since Angular 14, developers have had the option to create standalone components by adding the standalone flag to components, directives, and pipes. This allowed for a new way of structuring applications, reducing the reliance on modules when they weren't necessary. With Angular 19, this standalone approach is no longer optional—it's the standard.

    What This Means for New Components

    • No More standalone: true: When generating a new component, you no longer need to add the standalone property and set it to true. The framework assumes that new components are standalone unless specified otherwise.
    • Simplified Codebase: This change reduces boilerplate code and simplifies the structure of your Angular applications, making them more maintainable and easier to understand.
    • Future-Proofing: Embracing standalone components aligns your applications with the future direction of Angular, ensuring long-term compatibility and access to new features.

    Updating Existing Module-Based Applications

    If your current application relies on modules and non-standalone components, you can still update to Angular 19 without major overhauls:

    • Use the ng update Command: Running ng update will automatically adjust your existing components. It adds the standalone: false property to components, directives, and pipes that are not standalone.
    • Reversing the Explicit Declaration: Previously, you had to explicitly set standalone: true for standalone components. Now, you need to explicitly set standalone: false for components that depend on modules.
    • Continued Support for Modules: Module-based components will continue to function as they always have. The framework supports both approaches, giving you flexibility during the transition.

    Angular 19 brings signals and signal-related APIs out of developer preview, marking them as stable and ready for production use. Signals offer a reactive approach to handling data changes within your application, providing more efficient and predictable state management.

    Enhancements to ViewChild and ViewChildren

    • Signals for Querying Elements: The ViewChild and ViewChildren APIs now return signals. This means when you query elements in your templates, you receive a signal that updates automatically when the element changes.
    • Reactive Updates: This reactive behavior ensures that your component's view remains in sync with the underlying data, reducing the need for manual change detection.

    Transitioning from Decorators to Functions

    • New input() and output() Functions: Alongside the traditional @Input and @Output decorators, Angular now provides input() and output() functions as a modern alternative.
    • Recommended Usage: These functions are considered the preferred method for handling inputs and outputs in Angular 19, offering better integration with signals.
    • Automated Migration: To ease the transition, Angular CLI includes schematics that can automatically convert your code. Running ng generate @angular/core:signals will update your application by replacing decorators with their corresponding functions.

    Benefits of Adopting Signals

    • Cleaner Code: Using signal functions leads to more concise and readable code.
    • Improved Performance: Signals offer a more efficient way to manage state changes, potentially enhancing application performance.
    • Alignment with Angular's Future: As signals are poised to become a fundamental part of Angular's architecture, adopting them now prepares your application for future updates.

    Introducing Experimental Signal Functions: linkedSignal and resource

    Angular 19 introduces two new experimental functions for creating signals, designed to address specific use cases in state management.

    The linkedSignal Function

    • Purpose: Creates a mutable signal that is initialized with a function tracking other dependencies.
    • Behavior: If the tracked dependency changes, the linkedSignal resets to the new initial state, discarding any changes made after initialization.
    • Use Cases: Useful in scenarios where a signal needs to both change over time and stay synchronized with another signal or value.

    The resource Function

    • Purpose: Manages asynchronous values, such as data from HTTP requests, within a signal.
    • Structure: You provide an object with two methods:
      • request Method: Defines the dependencies or parameters (e.g., a user ID) that trigger data fetching.
      • loader Method: Specifies how to fetch the data when dependencies change (e.g., making an HTTP request).
    • Benefits: Simplifies the handling of asynchronous operations, integrating them seamlessly into the signal-based state management system.

    Current Status

    Both linkedSignal and resource are experimental and may change in future releases. However, they offer a glimpse into the potential for more advanced and flexible state management in Angular applications.

    Incremental Hydration in Developer Preview

    Angular 19 introduces support for incremental hydration, a feature that enhances server-side rendering (SSR) by optimizing how and when parts of your application become interactive on the client side.

    Understanding Incremental Hydration

    • Traditional SSR Limitations: In standard SSR, even though the server sends a fully rendered HTML page, the client still needs to download the entire Angular framework to make the page interactive.
    • The Incremental Approach: Incremental hydration allows you to specify parts of your template that should be hydrated (i.e., become interactive) later, rather than immediately upon page load.
    • Using the defer Directive: By wrapping components with the defer directive, you instruct Angular to delay the hydration of those components until a specified trigger occurs (e.g., when the component scrolls into view).

    Benefits of Incremental Hydration

    • Performance Gains: Reduces the initial amount of JavaScript that needs to be downloaded, leading to faster page loads.
    • Immediate Content Visibility: Unlike lazy loading, the content is already rendered and visible to the user; only the interactivity is delayed.
    • Optimized Resource Usage: By deferring hydration, you ensure that only necessary code is loaded when required.

    Implementing Incremental Hydration

    • Enabling the Feature: Incorporate the withIncrementalHydration function into your application's setup process during bootstrapping.
    • Configuring Hydration Triggers: Define when and how deferred components should be hydrated based on user interactions or other conditions.

    Marking Non-Interactive Sections

    • Never Hydrate Option: You can mark certain areas of your page as never requiring hydration if they don't need to be interactive.
    • Advantages: Prevents unnecessary downloading of JavaScript code for static content, further enhancing performance.

    Event Replay Now Enabled by Default

    In applications using server-side rendering, there's often a brief period where the client-side JavaScript hasn't fully loaded, but users can still interact with the page. Angular 19 addresses this by enabling event replay by default.

    How Event Replay Works

    • Capturing Interactions: User events, such as clicks or form inputs, are captured even if the corresponding JavaScript hasn't loaded yet.
    • Replaying Events: Once the client-side code is ready, Angular replays these events, ensuring that user interactions are not lost.
    • User Experience: This results in a seamless experience where the application responds to user actions without noticeable delays or missed interactions.

    Enhanced Routing with the ServerRoute Interface

    Angular 19 introduces improvements to routing, giving developers more control over how and when routes are rendered.

    New Routing Capabilities

    • Using ServerRoute Interface: Instead of the standard Route interface, you can now use ServerRoute to define your application's routes.
    • Setting Render Modes: Assign a mode to each route to specify whether it should be rendered on the server during pre-rendering, or only on the client.
    • Dynamic Pre-Rendering: Define functions that run during the build process to determine which dynamic routes to pre-render, such as pages with parameters that depend on external data sources.

    Benefits for Dynamic Content

    • Static Site Generation: Allows you to pre-render pages with dynamic content, like blog posts or product pages, resulting in faster load times and better SEO.
    • Flexibility: Offers fine-grained control over the rendering process, enabling you to optimize each route based on its specific needs.

    Progress Towards Zone-Less Angular

    While not fully realized in Angular 19, the framework is moving towards eliminating the need for Zone.js, thanks to the adoption of signals.

    Current State

    • Disabling Zone.js: Since Angular 18, developers have had the option to disable Zone.js, although it's not yet fully stable.
    • Future Expectations: As signals become more integrated into Angular's core, it's anticipated that zone-less applications will become the standard, potentially as early as Angular 20.

    Implications

    • Performance Improvements: Removing Zone.js can lead to lighter applications and faster execution.
    • Simplified Change Detection: Signals offer a more direct way to manage change detection without relying on zones.

    These are the new features and enhancements that Angular 19 brings to the table, embracing standalone components, signals, incremental hydration, event replay, and improved routing.

    Happy coding with Angular 19! 🚀


    Share on