/Angular-Component-Communication

Angular (20+) Observables and Signal using Input/Output and Signal Input/Output

Primary LanguageTypeScript

Angular (19+) Observables Vs Signal using @Input/@Output playground and Signal Input/Output πŸ”Š

Demo

Demo


Modern practices latest final signal-based API is implementing πŸš€

βœ… @NgModule  β†’ Standalone component
βœ… *ngFor, *ngIf  β†’ Modern control flow: @if, @for
βœ… Parent emits updates through writableSignal() following the Modern `Signal-Based Component Architecture Pattern` (Service (Shared State) ←→ Parent (Local State) ←→ Child (Pure Input))
βœ… ngOnInit() + subscribe() + contructor based inject β†’ Use reactive Signals + computed() 
βœ… contruct-based DI injection β†’ inject(HttpClient) 
βœ… Better Ts notation β†’ Protected + readonly template properties for protection and mutability control
βœ… Two-Way Binding (Old Way) β†’ signal-input-pattern 

NOTES:

When passing values from a P -> C component using the @Input, these values are not available in the constructor = Avoids running Angular-specific logic or accessing @Input properties, as they are not yet set.

If you need to react to changes in @Input values beyond initialization, consider using the ngOnChanges() lifecycle hook

constructor()

  • Called first, before any Angular lifecycle hooks.
  • Used to initialise the component instance.
  • Runs before Angular has fully initialized the component.
  • Not safe access @Input values

ngOnInit()

  • called after the constructor, after the first ngOnChanges()
  • Safe for access @Input values
  • Runs after the constructor and after Angular sets up the component's bindings.

πŸ’― Thanks!

Now, don't be an stranger. Let's stay in touch!

leolanese’s GitHub image
πŸ”˜ Linkedin: LeoLanese
πŸ”˜ Twitter: @LeoLanese
πŸ”˜ DEV.to: Blog
πŸ”˜ Questions / Suggestion / Recommendation: developer@leolanese.com