
Nov, 28th 2024
Simplifying Software Development with Interfaces in C#
by Moltech Solutions
As one of the most popular frameworks for building modern web applications, Angular continues to evolve — this time with version 19. The latest release focuses on boosting developer productivity, enhancing performance, and delivering a smoother user experience. In this blog post, we’ll take a closer look at the standout features in Angular v19, explore how they can benefit your projects, and share key tips to help you migrate seamlessly.
In Angular v19, Incremental Hydration has been introduced to enhance server-side rendering (SSR).
Incremental Hydration is a new feature introduced in Angular v19 that enables selective loading and hydration of application parts as needed. Instead of hydrating the entire app upfront, Angular now allows components to be loaded and activated gradually, based on user interactions.
Improved Performance: By reducing the initial load time, Incremental Hydration makes your application faster and more responsive. Only essential parts of the app are hydrated initially, improving perceived performance.
Efficient resource usage: Reduces JavaScript execution time by avoiding unnecessary hydration of non-visible components.
Better User Experience: Users can start interacting with the app sooner, even if all components are not fully loaded.
i.e example :
1
2
3
4
import { provideClientHydration, withIncrementalHydration } from '@angular/platform-browser';
// ...
provideClientHydration(withIncrementalHydration());
1
2
3
@defer (hydrate on viewport) {
<shopping-cart />
}
1. Enable SSR with Angular Universal (if not already):
1
ng add @nguniversal/express-engine
2. Make your app compatible with hydration: Add @angular/platform-browserwith hydration enabled in main.ts:
1
2
3
4
5
6
7
8
9
10
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app/app.component';
import { importProvidersFrom } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
bootstrapApplication(AppComponent, {
providers: [
importProvidersFrom(BrowserModule.withServerTransition({ appId: 'serverApp' })),
],
}).catch(err => console.error(err));
Event Replay is a new feature in Angular v19 that enhances the hydration process in server-side rendered (SSR) applications.
Event Replay is a feature that captures user events during the initial load of the application and replays them once the necessary code is available. This ensures that user interactions are not lost or ignored while the app is still loading.
Previously, if a user clicked a button or typed into a form before the app was fully hydrated, those actions could be lost. Now, with Event Replay, Angular records these events and re-applies them once the related components are ready.
During SSR, the HTML is pre-rendered and sent to the browser. But until hydration completes, the page isn’t “interactive” from Angular’s perspective. If a user interacts with the page during this time:
Without Event Replay: The interaction is ignored or lost.
With Event Replay: The interaction is preserved and replayed, so the user never experiences broken functionality.
Smooth User Experience: Users can interact with the app immediately, without waiting for all JavaScript to load.
Smoother hydration process: Users can interact with the page even before Angular takes control.
Reduces race conditions: Especially for fast typers or impatient clickers
Increased Engagement: By capturing and replaying events, users feel that the app is responsive and interactive from the start.
1
2
3
4
5
6
// For new projects the Angular CLI will generate this code by default
bootstrapApplication(App, {
providers: [
provideClientHydration(withEventReplay())
]
});
What is Route-Level Render Modes?
Angular v19 introduces the ability to configure how each route in your application is rendered. You can choose between server-side rendering, client-side rendering, or prerendering for each route, depending on your app’s needs.
This means you can now define different rendering strategies per route, giving you more flexibility and performance control.
With this feature, you can now:
Use SSR for SEO-critical pages
Use SSG for static content
Use CSR for interactive/dynamic sections
All within the same Angular app.
Example Usage
You can define the render mode per route in your app.routes.ts file:
Flexibility: You can optimize each route for performance and user experience based on its specific requirements.
Improved Performance: By choosing the appropriate render mode, you can reduce load times and improve the overall performance of your application.
Smaller bundle sizes: for CSR-only routes
You can define the render mode per route in your app.routes.ts file:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
export const routes: Routes = [
{
path: 'home',
component: HomeComponent,
render: 'server' // Server-side Rendering (SSR)
},
{
path: 'blog',
component: BlogComponent,
render: 'static' // Static Site Generation (SSG)
},
{
path: 'dashboard',
component: DashboardComponent,
render: 'client' // Client-side Rendering (CSR)
}
];
In Angular v19, HMR has been further improved for faster development cycles and a smoother developer experience out of the box.
What is Hot Module Replacement?
Hot Module Replacement (HMR) is a feature that allows developers to update styles and templates without refreshing the entire page. This means that changes can be applied instantly, making the development process faster and more efficient.
HMR injects only the changed modules into the browser while preserving the app’s current state
Faster Development: Instant updates mean less time waiting for changes to take effect.
Better Workflow: Developers can see the results of their changes immediately, leading to a more efficient and enjoyable development experience.
Improved productivity: iterate and debug UI changes instantly
Preserves application state: e.g., no loss of input data during development
Enable HMR using the CLI:
1
ng serve --hmr
What are Standalone Components?
Standalone Components are a new feature in Angular v19 that allows components to be used without needing to declare them in an NgModules. This simplifies the code and makes it easier to manage and maintain.
Instead of declaring a component inside a module, you can define it as standalone: true, making it self-contained and more reusable.
Why Is It Used?
NgModules were traditionally used to group components and manage dependencies. However, this often led to boilerplate code, tight coupling, and confusion about where components should be declared or imported.
Standalone components solve this by:
Making components self-contained.
Encouraging a modular and scalable architecture.
Simplifying testing and lazy loading.
Simplified Code: With fewer dependencies, your codebase becomes cleaner and easier to understand.
Improved Maintainability: Standalone components are easier to manage and update, reducing the risk of errors and bugs.
Simplified testing — no need to set up test modules.
No need for NgModules — reduces boilerplate.
Simplified testing — no need to set up test modules.
1. Old Way (With Module):
1
2
3
4
5
@NgModule({
declarations: [MyComponent],
imports: [CommonModule],
})
export class MyModule {}
2. With Standalone Component:
1
2
3
4
5
6
7
8
9
10
import { Component } from '@angular/core';
import { CommonModule } from '@angular/common';
@Component({
selector: 'app-my-component',
standalone: true,
imports: [CommonModule],
template: `<p>Hello from a standalone component!</p>`,
})
export class MyComponent {}
What is the New Time Picker Component?
Angular v19 introduces a new Time Picker component, allowing users to select time in a more intuitive and user-friendly way. This component has been a much-requested feature and is now available to enhance your application’s user interface.
With Angular v19, you can now use a native, consistent, and accessible time picker component directly from Angular’s component toolkit.
Enhanced User Interface: The new Time Picker provides a modern and intuitive way for users to select time.
Increased Usability: By offering a dedicated component for time selection, your application becomes more user-friendly and accessible.
Out-of-the-box support — No need for custom time pickers or third-party packages
Easy integration — Works seamlessly with Angular forms (both Template-driven and Reactive)
Material design-ready — Fully themed and consistent with Angular Material UI
1
2
3
4
5
6
<mat-form-field>
<mat-label>Pick a time</mat-label>
<input matInput [matTimepicker]="picker" />
<mat-timepicker-toggle matIconSuffix [for]="picker" />
<mat-timepicker #picker />
</mat-form-field>
Step intervals for minutes (e.g., 5, 10, 15 minutes)
AM/PM toggle or 24-hour format
Minimum and maximum allowed times
Validation support for required fields
What is the Enhanced Theming API?
The Enhanced Theming API in Angular v19 simplifies the process of creating custom themes for your application. This new API provides more flexibility and control over the look and feel of your app.
The new API is built using CSS variables, allowing dynamic theming, better support for dark/light modes, and real-time theme switching without recompiling styles.
Why Is It Used?
Previously, theming in Angular Material relied heavily on SCSS mixins, which made real-time theme changes difficult. You had to predefine themes and switch them using complex workarounds or page reloads. With the enhanced theming API:
You can define themes using CSS custom properties
Apply multiple themes dynamically
Create custom component styles more easily
Easier Customization: Creating and applying custom themes is now simpler and more straightforward.
Consistent Design: The Enhanced Theming API ensures that your application’s design is consistent and cohesive.
Scoped theming: Apply a specific theme only to a certain section of your app.
Better dark mode support: More consistent and maintainable.
Example: Defining a Theme with CSS Variables
1
2
3
4
5
6
:root {
--mdc-theme-primary: #6200ea;
--mdc-theme-on-primary: #ffffff;
--mdc-theme-secondary: #03dac6;
--mdc-theme-on-secondary: #000000;
}
Then use these variables in your components or override Material styles:
1
2
3
4
.my-custom-button {
background-color: var(--mdc-theme-primary);
color: var(--mdc-theme-on-primary);
}
To support dynamic theming in ts file :
1
document.documentElement.style.setProperty('--mdc-theme-primary', '#ff5722');
What is Two-Dimensional Drag and Drop?
In Angular v19, the Angular CDK (Component Dev Kit) introduces support for Two-Dimensional Drag and Drop — allowing elements to be dragged both horizontally and vertically within a defined container or grid.
Previously, the CDK supported drag-and-drop mainly in one direction (typically vertical). With this enhancement, you can now drag items freely in both X and Y axes, enabling advanced UI patterns like grid reordering, visual layout builders, and dashboards.
Modern interfaces often require more than simple vertical lists — think Kanban boards, customizable dashboards, or design tools. Two-dimensional drag-and-drop allows users to interact with the UI in a more intuitive and flexible way.
Supports grid-based layouts — Great for visual editors or dashboard widgets.
Customizable drop zones and containers.
Fully integrated with Angular CDK — no need for third-party libraries.
Enhanced Functionality: Two-dimensional drag and drop opens up new possibilities for creating interactive and dynamic user interfaces.
1
2
3
4
5
6
7
8
9
10
11
<div
cdkDropList
cdkDropListOrientation="mixed" <!-- specify mixed orientation -->
>
@for (item of mixedTodo; track item) {
<div cdkDrag>
{{item}}
<mat-icon cdkDragHandle svgIcon="dnd-move"></mat-icon>
</div>
}
</div>
Module Import: Make sure you import the necessary Angular CDK module.
1
2
3
4
5
6
import { DragDropModule } from '@angular/cdk/drag-drop';
@NgModule({
imports: [DragDropModule],
})
export class AppModule {}
What are Linked Signals and Resources?
Linked Signals and Resources are new APIs in Angular v19 for managing state and asynchronous data. These APIs simplify the process of handling complex state and data fetching in your application.
Linked Signals and Resources are part of Angular’s move toward a more reactive programming model using Signals. This concept helps make state management and side effects more predictable, efficient, and declarative.
Signals are a reactive primitive that tracks and reacts to changes in values.
Linked Signals let you combine or derive new signals based on other signals.
Resources are lifecycle-aware constructs that work with signals to manage things like subscriptions, timers, or HTTP requests cleanly.
Previously, Angular relied heavily on services, RxJS, and manual ngOnDestroy() logic to manage state and side effects.
With Linked Signals and Resources:
You can now track changes to values reactively without subscriptions.
You can create derived state from other signals.
You can automatically clean up side effects tied to component lifecycle.
Simplified State Management: Managing state becomes easier and more efficient with Linked Signals and Resources.
Better Data Handling: These new APIs provide a more streamlined way to handle asynchronous data, improving the overall performance of your application.
Improves performance and memory management
Automatic cleanup of side effects (like unsubscribing from observables)
1
2
3
4
5
6
7
8
9
10
11
12
const options = signal(['apple', 'banana', 'fig']);
// Choice defaults to the first option, but can be changed.
const choice = linkedSignal(() => options()[0]);
console.log(choice()); // apple
choice.set('fig');
console.log(choice()); // fig
// When options change, choice resets to the new default value.
options.set(['peach', 'kiwi']);
console.log(choice()); // peach
What are the Security Improvements?
Angular v19 introduces several enhanced security features that make your applications safer by strengthening DOM sanitization, tightening CSP (Content Security Policy) support, and improving framework-level safeguards. These updates help protect against common web vulnerabilities like Cross-Site Scripting (XSS) and injection attacks while improving compliance with modern security standards.
Security is a core pillar of web development. As applications become more dynamic and interactive, the risk of unintended vulnerabilities increases. Angular v19 helps developers stay ahead by:
Reducing attack surface
Improving compatibility with strict security environments
Enabling secure-by-default behavior
Improved handling of untrusted HTML and inputs
Better protection against XSS in edge cases
Easier to configure Angular apps to comply with CSP rules
Helps in environments where inline scripts/styles are blocked
Enforces safer DOM usage by requiring explicit handling of HTML, URLs, etc.
Helps prevent DOM-based XSS when dealing with dynamic content
Better detection of unsafe bindings at compile-time
Encourages more secure coding patterns
Example: Trusted Types Protection
1
2
3
4
5
// Angular enforces safe HTML usage
const myHtml = '<img src="x" onerror="alert(1)" />';
// Unsafe binding will be sanitized or blocked:
<div [innerHTML]="myHtml"></div> // Will not trigger alert due to sanitization
Migrating to a new version of Angular can seem daunting, but with the right approach, it can be a smooth and straightforward process. Here are some tips to help you migrate to Angular v19:
1 . Update Angular CLI and Core:
2. Address Deprecation Warnings:
3. Test Thoroughly:
4. Leverage Automatic Migrations:
5. Update Dependencies:
6. Review and Refactor Code:
7. Enable Standalone Components:
8. Utilize New APIs:
Angular v19 is packed with features that make it easier to build fast, efficient, and secure web applications. Whether you’re a seasoned developer or just starting out, these updates will help you create better apps with less effort.
Whether you’re a seasoned Angular developer or just starting out, Angular v19 offers tools and features that will help you build better, faster, and more secure web applications. Embrace these new updates and take your projects to the next level!
Success in today's connected, fast-paced digital market depends on web applications. We create secure, scalable, and robust web apps tailored specifically for your business needs.