DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Last call! Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Rediscovering Angular: Modern Advantages and Technical Stack
  • The Role of JavaScript Frameworks in Modern Web Development
  • The Power of @ngrx/signalstore: A Deep Dive Into Task Management
  • Angular vs. Flutter for Web App Development: Know Which One Is Best?

Trending

  • Transforming AI-Driven Data Analytics with DeepSeek: A New Era of Intelligent Insights
  • AI-Based Threat Detection in Cloud Security
  • How to Practice TDD With Kotlin
  • Memory Leak Due to Time-Taking finalize() Method
  1. DZone
  2. Coding
  3. Frameworks
  4. Angular Input/Output Signals: The New Component Communication

Angular Input/Output Signals: The New Component Communication

Angular 17’s Input and Output Signals simplify component communication with optimized reactivity, transformations, and memoized values.

By 
Aliaksandr Mirankou user avatar
Aliaksandr Mirankou
·
Dec. 10, 24 · Analysis
Likes (1)
Comment
Save
Tweet
Share
6.4K Views

Join the DZone community and get the full member experience.

Join For Free

Angular 17 brings a lot of brand-new features. Some focus on performance, others on tooling and build improvements, but perhaps one of the most exciting enhancements is in component interaction. This version officially introduces signals — a revolutionary way of managing reactivity in Angular applications.

In this article, we’ll explore how to use signals for parent-child component communication. We’ll dive into what signals are, how they simplify inputs and outputs, and the additional features they bring to the table.

What Are Signals?

At their core, signals are wrappers around a value that notify any interested consumers whenever that value changes. This means that when a signal is updated, Angular efficiently tracks where it’s used and optimally re-renders only the affected parts of the DOM. The result? A highly reactive and performance-optimized framework.

While we won’t dive deeply into the fundamentals of signals, this article focuses on how signals transform parent-child component interaction, enabling a cleaner, more reactive way of working with inputs and outputs.

The New Approach With Inputs

Traditionally, passing data from a parent to a child component in Angular relies on the @Input decorator. With signals, Angular offers a new way to define inputs using InputSignal. Let’s explore this with an example:

TypeScript
 
// child.component.ts

import { Component, input, InputSignal } from '@angular/core';

@Component({
  selector: 'app-child',
  template: `
    <div>{{ carBrand() }}</div>
    <div>{{ carModel() }}</div>
  `,
  standalone: true,
})
export class ChildComponent {
  public carBrand: InputSignal<string> = input<string>();
  public carModel: InputSignal<string> = input<string>('');
}


In this example, carBrand and carModel are declared as InputSignal properties. Signals, unlike traditional inputs, are read-only by default and accessed like functions. The parent component can pass data to these inputs just like before:

TypeScript
 
// parent.component.ts

import { Component } from '@angular/core';
import { ChildComponent } from './child.component';

@Component({
  selector: 'app-parent',
  template: `
    <app-child [carBrand]="'Porsche'" [carModel]="'Cayenne'"></app-child>
  `,
  standalone: true,
  imports: [ChildComponent],
})
export class ParentComponent {}


Also, we can mark an input as a required input. It can be helpful in case you want to obligate a consumer component to pass the data your child component needs:

TypeScript
 
public carBrand: InputSignal<string> = input.required<string>();


If the parent omits this input, Angular will throw an error, ensuring component integrity:

Markdown
 
Missing binding for required input **carBrand** of component **ChildComponent**.


The New Outputs

The traditional way to send data from a child to a parent component involves the @Output decorator with EventEmitter. Signals introduce OutputEmitterRef, a signal-based mechanism for handling outputs. Let’s look at an example:

TypeScript
 
// child.component.ts

import { Component, input, InputSignal, output, OutputEmitterRef } from '@angular/core';

@Component({
  selector: 'app-child',
  template: `
    <div>{{ carBrand() }}</div>
    <div>{{ carModel() }}</div>
    <button (click)="chooseCar.emit({ carBrand: carBrand(), carModel: carModel() })">
      Choose a Car
    </button>
  `,
  standalone: true,
})
export class ChildComponent {
  public carBrand: InputSignal<string> = input.required<string>();
  public carModel: InputSignal<string> = input<string>('');
  public chooseCar: OutputEmitterRef<{ carBrand: string; carModel: string }> = output<{
    carBrand: string;
    carModel: string;
  }>();
}


The parent component can handle this output in a familiar way:

TypeScript
 
// parent.component.ts

@Component({
  selector: 'app-parent',
  template: `
    <app-child
      [carBrand]="'Porsche'"
      [carModel]="'Cayenne'"
      (chooseCar)="chooseCardHandler($event)">
    </app-child>
  `,
  standalone: true,
  imports: [ChildComponent],
})
export class ParentComponent {
  public chooseCardHandler(carInfo: { carBrand: string; carModel: string }): void {
    console.log(carInfo);
  }
}


This new output mechanism retains the simplicity of traditional outputs while integrating seamlessly with Angular’s reactive ecosystem.

Benefits of Signals for Inputs and Outputs

One of the biggest advantages of using signals for inputs is their inherent reactivity. Each time an input value changes, Angular automatically marks the component for updates during the next change detection cycle. However, unlike traditional mechanisms, signals optimize this process by only updating the specific parts of the DOM that depend on the changed value.

With signals, there’s no longer a need for OnChanges. For example, you can use input signals with the computed function to dynamically calculate derived values. Let’s say we want to combine the car model and brand into a single field — this can now be achieved reactively:

TypeScript
 
import { Component, computed, effect, input, InputSignal, output, OutputEmitterRef, Signal } from '@angular/core';

@Component({
    selector: 'app-child',
    template: `
        <div>{{ carBrand() }}</div>
        <div>{{ carModel() }}</div>
        <button (click)="chooseCar.emit({ carBrand: carBrand(), carModel: carModel() })">
            Choose a Car ({{ carFullName() }})
        </button>
    `,
    standalone: true,
})
export class ChildComponent {
    public carBrand: InputSignal<string> = input.required<string>();
    public carModel: InputSignal<string> = input<string>('', { alias: 'customCarModel' });
    public chooseCar: OutputEmitterRef<{ carBrand: string; carModel: string }> = output<{
        carBrand: string;
        carModel: string;
    }>();

    public carFullName: Signal<string> = computed(() => `${this.carModel()} ${this.carBrand()}`);
}


Each time the carBrand or carModel inputs change, the computed signal recalculates the value and carFullName holds the computed value.

Signals also simplify handling side effects. By using the effect function, we can execute logic whenever an input value changes. For example, imagine you need to send analytics data whenever the carBrand input changes. effect function automatically triggers whenever the dependent input changes, eliminating the need for complex manual handling:

TypeScript
 
import { Component, computed, effect, input, InputSignal, output, OutputEmitterRef, Signal } from '@angular/core';

@Component({
    selector: 'app-child',
    template: `
        <div>{{ carBrand() }}</div>
        <div>{{ carModel() }}</div>
        <button (click)="chooseCar.emit({ carBrand: carBrand(), carModel: carModel() })">
            Choose a Car ({{ carFullName() }})
        </button>
    `,
    standalone: true,
})
export class ChildComponent {
    public carBrand: InputSignal<string> = input.required<string>();
    public carModel: InputSignal<string> = input<string>('', { alias: 'customCarModel' });
    public chooseCar: OutputEmitterRef<{ carBrand: string; carModel: string }> = output<{
        carBrand: string;
        carModel: string;
    }>();

    public carFullName: Signal<string> = computed(() => `${this.carModel()} ${this.carBrand()}`);

    constructor() {
        effect(() => {
            this.sendAnalytics(this.carBrand());
        });
    }

    private sendAnalytics(carBrand: string): void {
        // perform sending analytics
    }
}


Notably, effect ensures that actions are performed only when necessary (only when the signal in effect function is changed) and always reflects the most up-to-date state.

Another significant benefit is memoization. Signals cache their computed values and only recalculate them when dependencies change. All of these simplify the development flow and can enhance the application performance.

Conclusion

The introduction of input and output signals in Angular represents a major step forward in how we manage component communication. We gain a more reactive and efficient approach to passing and receiving data, significantly reducing the boilerplate and complexity that traditional methods often require. This innovation doesn’t just enhance developer experience — it also brings performance benefits.

If you’re working on modern Angular applications, this is the perfect opportunity to explore signals and see how they can simplify your workflow. Start by replacing traditional @Input and @Output with signal-based alternatives in your components. Experiment with features like computed and effect to create reactive and maintainable logic, and explore transformers to customize your data flow effortlessly.

Signal AngularJS Framework

Opinions expressed by DZone contributors are their own.

Related

  • Rediscovering Angular: Modern Advantages and Technical Stack
  • The Role of JavaScript Frameworks in Modern Web Development
  • The Power of @ngrx/signalstore: A Deep Dive Into Task Management
  • Angular vs. Flutter for Web App Development: Know Which One Is Best?

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!