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>;
}
๐ง 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';
}
๐ถ 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>;
}
๐ฏ 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());
});
}
}
๐ 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.