javascript / intermediate
Snippet
Type-safe Signal Inputs
Signal inputs are a modern alternative to the @Input decorator. They provide better type safety, especially for required inputs, and integrate seamlessly with other reactive features like computed signals and effects.
snippet.js
javascript
1
2
3
4
5
6
7
8
9
10
import { Component, input } from '@angular/core';@Component({...})export class UserProfileComponent {// Required signal inputuserId = input.required<string>();// Optional signal input with default valueisAdmin = input(false);}
angular
Breakdown
1
input.required<string>()
Defines an input that must be provided by the parent, returning a Signal<string>.
2
input(false)
Defines an optional input with a default value of false.