Angular 20 introduces input() API for component communication

Day 26 of #100DaysOfCode 𝐂𝐨𝐦𝐦𝐮𝐧𝐢𝐜𝐚𝐭𝐢𝐨𝐧 𝐛𝐞𝐭𝐰𝐞𝐞𝐧 𝐜𝐨𝐦𝐩𝐨𝐧𝐞𝐧𝐭: 𝐢𝐧𝐩𝐮𝐭 () Communication between components is a core concept in Angular. With Agular we have the decorator @𝘐𝘯𝘱𝘶𝘵(), used to pass data from a parent component to a child component, but Angular 20 introduce the new signal-based 𝘪𝘯𝘱𝘶𝘵() API. 𝐢𝐧𝐩𝐮𝐭() is used for the same purpose. Imagine a user management application where we have a list of users in a parent component, and we want to display a user's details in a child component. It's like a bulletin board where the parent has all the information and decides what information it wants to share with its children. (𝘤𝘰𝘯𝘧𝘦𝘳𝘴 𝘪𝘮𝘢𝘨𝘦). • The value are accessible through a function ( e.g. : user() ) • The inputs are readonly • The input should be declare at the class level 𝐃𝐢𝐟𝐟𝐞𝐫𝐞𝐧𝐭𝐬 𝐰𝐚𝐲𝐬 𝐭𝐨 𝐮𝐬𝐞 𝐢𝐧𝐩𝐮𝐭(): 1. With a default's value :  𝘶𝘴𝘦𝘳𝘯𝘢𝘮𝘦 = 𝘪𝘯𝘱𝘶𝘵('𝘈𝘯𝘰𝘯𝘺𝘮𝘰𝘶𝘴'); 2. Required input : 𝘶𝘴𝘦𝘳 = 𝘪𝘯𝘱𝘶𝘵.𝘳𝘦𝘲𝘶𝘪𝘳𝘦𝘥<𝘜𝘴𝘦𝘳>(); 3. Input with transformation: 𝘯𝘢𝘮𝘦 = 𝘪𝘯𝘱𝘶𝘵('', { 𝘵𝘳𝘢𝘯𝘴𝘧𝘰𝘳𝘮: (𝘷𝘢𝘭𝘶𝘦: 𝘴𝘵𝘳𝘪𝘯𝘨) => { 𝘳𝘦𝘵𝘶𝘳𝘯 𝘷𝘢𝘭𝘶𝘦.𝘵𝘰𝘜𝘱𝘱𝘦𝘳𝘊𝘢𝘴𝘦();  } }); 𝐊𝐞𝐲 𝐭𝐚𝐤𝐞𝐚𝐰𝐚𝐲𝐬: • @𝘐𝘯𝘱𝘶𝘵() is still the standard way to send data from parent → child • Starting from Angular 18+, input() offers a more modern, reactive, and signal-friendly alternative • Angular 20 strongly encourages the use of Input Signals for cleaner and more predictable component state #Angular #Frontend #TypeScript

  • text

To view or add a comment, sign in

Explore content categories