DEV Community

Arbi Jridi
Arbi Jridi

Posted on

Say Goodbye to ngOnChanges() ..Hello Signal @Input in Angular 20

Angular Signal @Input

With Angular 20, the @Input decorator got a signal-powered upgrade. You can now use Signals to receive input values reactively, making Angular components cleaner and more powerful.

What Are Signals?

Signals are reactive primitives introduced in Angular to help manage state and reactivity without external libraries like RxJS. They track dependencies and automatically update values when the source changes.

🎯 What’s New in Angular 20?

Angular 20 brings:

  • Signal-based inputs via @Input({ signal: true })
  • Cleaner reactivity without manual ngOnChanges
  • Seamless integration with signal-based components
  • Traditional vs Signal Input
  • Traditional Input @Input() name: string; You would need ngOnChanges or manual checks to respond to changes.

βœ… Input with Signals in Angular 20

import { Component, Input, signal } from '@angular/core';
@Component({
  selector: 'app-greeting',
  template: `<h1>Hello, {{ name() }}!</h1>`
})
export class GreetingComponent {
  @Input({ signal: true }) name: Signal<string>;
}
Enter fullscreen mode Exit fullscreen mode

🧠 Now, name is a signal, and you can call it as a function (name()), which automatically re-runs anything that depends on it when it changes.

πŸ“˜ Full Example: Parent to Child Communication Using Signal @Input

πŸ‘¨β€πŸ‘©β€πŸ‘§ Parent Component

@Component({
  selector: 'app-parent',
  template: `
    <input [(ngModel)]="userName" placeholder="Enter name" />
    <app-greeting [name]="userName"></app-greeting>
  `
})
export class ParentComponent {
  userName = 'َArbi';
}
Enter fullscreen mode Exit fullscreen mode

πŸ‘Ά Child Component with Input Signal

import { Component, Input, Signal } from '@angular/core';
@Component({
  selector: 'app-greeting',
  template: `
    <div class="greeting">Hello, {{ name() }}!</div>
  `
})
export class GreetingComponent {
  @Input({ signal: true }) name!: Signal<string>;
}
Enter fullscreen mode Exit fullscreen mode

🎯 Why Use Signal Inputs?

βœ… Benefits

  • No need for ngOnChanges
  • Easier to compose with computed signals
  • Automatic change detection
  • Fine-grained reactivity

🧩 Combine with computed() or effect()

import { computed, effect } from '@angular/core';
@Component({
  selector: 'app-user-info',
  template: `
    <p *ngIf="isLongName()">Long name detected</p>
  `
})
export class UserInfoComponent {
  @Input({ signal: true }) name!: Signal<string>;
  isLongName = computed(() => this.name().length > 5);
  constructor() {
    effect(() => {
      console.log('User name changed:', this.name());
    });
  }
}
Enter fullscreen mode Exit fullscreen mode

πŸ”š Conclusion

Angular 20’s support for signal-based @Input is a leap toward declarative and reactive Angular. You get cleaner code, automatic updates, and better performance.

If you’re building a modern Angular app with signals, this feature is a must-use.
Ω€Ω€Ω€Ω€Ω€Ω€Ω€Ω€Ω€Ω€Ω€Ω€Ω€Ω€Ω€Ω€Ω€Ω€Ω€Ω€Ω€Ω€
Thanks for reading and if you want more of this content about Angular and other cool stuff,
see my repo here :Github
my personal Blog : NgBlog

Top comments (0)

Some comments may only be visible to logged-in visitors. Sign in to view all comments.