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
Angular 20 introduces input() API for component communication
More Relevant Posts
-
🚀 Angular 21 just made form control development ridiculously easy. Remember when creating a custom form control meant implementing four methods, configuring obscure providers, and praying ControlValueAccessor behaved? Yeah… those days are gone. In my latest Medium article, I break down Angular's new Signal Forms API — a total game-changer for anyone building forms. You’ll learn how to: Replace verbose ControlValueAccessor code with one clean property. Build fully reactive, signal-powered custom form controls. Handle disabled and required states automatically. And yes… finally sleep at night instead of debugging forms at 2 AM. 💤 💡 If you’ve ever shouted “WHY is my form not updating?!” — this one’s for you. Read here 👉 https://lnkd.in/dBtYqbAc #Angular #WebDevelopment #SignalForms #Frontend #Angular21 #TypeScript #CodingHumor #DeveloperLife #ReactiveProgramming
To view or add a comment, sign in
-
Angular Schematics That Clean Up Your Code 🚀 Angular Tip: Automate Your Code Hygiene with a Custom Schematic! Have you ever opened a file in a large Angular project and seen a dozen unused imports just… sitting there? 👀 They don’t break anything — but they clutter your code, slow down reviews, and hint at deeper refactoring debt. Here’s the good news 👉 Angular gives us a way to automate that cleanup — with Schematics. 🧩 What’s a Schematic? A schematic in Angular is more than just scaffolding commands (ng generate component etc.). It’s a code transformation tool that can: Read and modify your TypeScript source files Apply project-wide refactors Integrate clean-up logic into your CI/CD pipelines 🧱 Real Example — Cleaning Unused Imports You can build a schematic that: Walks through all .ts files in your workspace. Uses the TypeScript compiler API to detect unused imports. Removes them safely — without touching the rest of your code. It’s like running eslint --fix — but framework-aware, and customizable to your team’s rules. ng g workspace-schematic cleanup-imports And once registered, you can run it anytime: ng run my-workspace:cleanup-imports ⚙️ Why It’s Powerful Enforces consistent hygiene across all projects. Integrates with CI/CD to keep your repo spotless. Saves time during code reviews. Scales beautifully for enterprise Angular apps. 🔍 Bonus Tip Combine it with a linter rule or a postinstall script: npm run lint && ng run my-workspace:cleanup-imports so your codebase stays clean automatically after every dependency update. 🧠 Final Thought Angular Schematics are underused outside library scaffolding — but they can be your secret weapon for keeping a massive workspace healthy and modern. 💬 Curious to see a live example of a schematic that removes unused imports? Drop a comment below — I’m considering open-sourcing one for the community. 💪 #Angular #TypeScript #CodeQuality #DeveloperExperience #CleanCode #DevTools
To view or add a comment, sign in
-
Custom Validators in Angular Signal Forms (You Probably Need This) Custom validators are one of those things you'll definitely need when building real-world forms. But if you've been wondering how they work with Angular's new Signal Forms API, you're in the right place. Today we'll migrate a form with custom validation from Reactive Forms to Signal Forms, and I think you'll be pleasantly surprised by how straightforward it is. The syntax changes are minimal, and the result is cleaner, more reactive code. Preview: Angular Reactive Form Behavior We'll Rebuild with Signal Forms Ok, here's the form for today's example: It's pretty standard, just a username, email, and a submit button. Let's walk through the validation quickly so we can see what behavior we're going to replicate. When we click into the username field and blur out, we immediately get a required message letting us know we need to fill out this field: Then, when we type a special character, we get an invalid format message: If we replace this with a letter or number, now we https://lnkd.in/gipRggip
To view or add a comment, sign in
-
Custom Validators in Angular Signal Forms (You Probably Need This) Custom validators are one of those things you'll definitely need when building real-world forms. But if you've been wondering how they work with Angular's new Signal Forms API, you're in the right place. Today we'll migrate a form with custom validation from Reactive Forms to Signal Forms, and I think you'll be pleasantly surprised by how straightforward it is. The syntax changes are minimal, and the result is cleaner, more reactive code. Preview: Angular Reactive Form Behavior We'll Rebuild with Signal Forms Ok, here's the form for today's example: It's pretty standard, just a username, email, and a submit button. Let's walk through the validation quickly so we can see what behavior we're going to replicate. When we click into the username field and blur out, we immediately get a required message letting us know we need to fill out this field: Then, when we type a special character, we get an invalid format message: If we replace this with a letter or number, now we https://lnkd.in/gipRggip
To view or add a comment, sign in
-
Dependency Injection in Angular: The Secret Behind Its Power and Simplicity Ever wondered how Angular magically gives you services like HttpClient, without you ever creating an instance yourself? That’s all thanks to Dependency Injection (DI) one of Angular’s most powerful (and often overlooked) features. 💡 In simple words: Dependency Injection means you don’t create dependencies manually, Angular does it for you. Instead of saying “create this service inside my component,” you just tell Angular “I need this service,” and it handles the rest. Think of it like ordering food at a restaurant 🍽️ You (the component) just place an order (request a dependency). The kitchen (Angular’s injector) prepares it and serves it to you fresh and ready! ⚙️ Why It Matters: ✅ Reusability: The same service instance can be shared across multiple components. ✅ Maintainability: You can easily swap one implementation with another (e.g., mock services for testing). ✅ Testability: Since dependencies are injected, not hard-coded, writing unit tests becomes much easier. ✅ Scoping Control: You can decide where a service should live app-wide or only within a specific feature module or component. 🌱 In Modern Angular (v14+): With Standalone Components, DI became even more flexible. You can now provide services directly inside components using the providers array no need for NgModules anymore! This means tighter encapsulation, faster bootstrapping, and cleaner architecture. 🚀 In short: Dependency Injection is what keeps Angular apps modular, scalable, and testable. It’s the invisible backbone that connects your logic layers smoothly without cluttering your components. ✨ The beauty of Angular DI: You focus on what you need, not how to create it. 💬 How do you organize your services and providers in Angular app-level, feature-level, or component-level? #Angular #WebDevelopment #Frontend #SoftwareEngineering #DependencyInjection #AngularDeveloper #CleanArchitecture #TypeScript #Programming
To view or add a comment, sign in
-
Standalone simplicity Modern Angular(v15+) no longer leans on heavy NgModules. With standalone components, you can build and use components, directives and pipes without registering them in a module. Since Angular 19 standalone is a default and don't need to explicitly set it to true. The official docs note that these standalone APIs “aim to streamline the authoring experience by reducing the need for NgModule” and can be adopted incrementally without breaking changes. That means less boilerplate and a lower barrier to entry. The real game changer is lazy loading. In the past you had to create a module for every feature you wanted to lazy‑load, which discouraged modular design. Standalone components make it trivial: instead of a loadChildren module, you use loadComponent and Angular splits each screen into its own bundle. One team even saw their main bundle shrink by half after migrating to standalone components. Routing, bootstrapping and dependency declarations are all simplified. These self‑contained components promote better reuse and testability. You can mix standalone and NgModule‑based components in the same project(but why would you? 😁), bootstrap the app with a single component, and import only the directives and pipes you need. Tools like the Angular Language Service handle imports automatically, and the new control‑flow syntax (@if, @for, @switch) and signals fit naturally into the standalone model. If Angular once felt complex, take another look. Standalone components strip away unnecessary abstractions, make lazy loading effortless and align the framework more closely with modern JavaScript. It’s a clear step toward a leaner, more approachable Angular. #Angular #WebDevelopment #FrontendDeveloper #ModernJavaScript
To view or add a comment, sign in
-
🚀 Angular Insight: Interpolation vs Signals In Angular, interpolation has long been the standard way to display data in templates. With the introduction of Signals in Angular 16 (and full integration in Angular 17+), Angular’s reactivity model has entered a new era of efficiency. ⚡ 🔹 What is Zone.js? Zone.js is the library Angular uses to automatically detect when something changes in the application — such as a user action, a timer, or an HTTP request — and then trigger change detection to update the view. While powerful, Zone.js runs change detection across the entire component tree, even when only a small piece of data changes. As a result, Angular re-checks parts of the UI that don’t actually need updating, which can reduce performance in larger or more complex applications. 🔹 Interpolation Displays component data in the template. Relies on Zone.js for global change detection. Simple to use but triggers updates across the full component or view. 🔹 Signals Represent reactive values that automatically update the UI when they change. Remove the dependency on Zone.js. Enable fine-grained reactivity, meaning only the part of the UI connected to the changed signal is updated — not the entire component. Deliver faster, cleaner, and more predictable updates. #Angular #Angular17 #AngularDevelopers #AngularTips #Signals #ZoneJS #FrontendDevelopment #WebDevelopment #JavaScript #TypeScript #ReactiveProgramming #FrontendEngineering #WebPerformance #ModernWeb #UIDevelopment #CleanCode #Programming #TechCommunity
To view or add a comment, sign in
-
-
🚀 Quick Tutorial: Master basic data display in Angular using string interpolation! Declare a public property in your component's TypeScript file, e.g., `message = 'Hello Angular!';`. Then, effortlessly display this data in your HTML template using `<h1>{{ message }}</h1>`. This fundamental technique instantly binds your component's data to the view, making your UIs dynamic and responsive! #Angular #FrontendDevelopment #WebDev #AngularTutorial #CodingTips
To view or add a comment, sign in
-
🔍 Angular Architecture Explained If you’re diving into Angular or aiming to strengthen your foundation, understanding its architecture is essential. Let’s break down the core building blocks that make every Angular application powerful and scalable 👇 🧩 1. Application Module (AppModule) The heart of your Angular app, where everything begins. Declares all components, services, and modules. Think of it as the main controller that bootstraps your application. ⚙️ 2. Components The building blocks of your UI. Each component includes a TypeScript class (logic), HTML template (view), and CSS (style). Example: HeaderComponent, SidebarComponent, ProductListComponent. 🖼️ 3. Templates (HTML & CSS) Define what users see on the screen. Angular enhances HTML with directives and data binding for a dynamic experience. CSS adds the finishing touch to your component’s look and feel. 🧠 4. Services Used to handle business logic and data operations. Ideal for fetching API data, sharing info between components, or performing background tasks. Keeps components clean and focused on presentation. 💉 5. Dependency Injection (DI) Angular’s way of injecting dependencies like services into components. Promotes modularity, testability, and scalability. Example: UserService can be injected into a component to fetch user data. 🧭 6. Routing (Navigation) Manages navigation in Single Page Applications (SPAs). Maps URL paths to components without reloading the entire page. Enables a seamless user experience across different views. 🔗 How It All Fits Together: AppModule ties everything together. Components use Templates for UI. Services provide data and logic via Dependency Injection. Routing handles navigation between components. This modular structure makes Angular apps scalable, maintainable, and efficient — perfect for modern web development! 🚀 #Angular #WebDevelopment #JavaScript #Frontend #AngularArchitecture #Coding #Developers #TechLearning #Programming
To view or add a comment, sign in
-
More from this author
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development