Skip to content

This repo is to explains Angular signals and real time examples how to create and update signals, use effects, convert from observable and create computed values. It includes the angular signal demo with multiple scenario...

Notifications You must be signed in to change notification settings

sonusindhu/angular-signals-examples

Repository files navigation

🎯 Angular Signals Examples

Angular TypeScript Live Demo License: Unlicense

πŸš€ A comprehensive collection of Angular Signals examples showcasing modern reactive programming

Master Angular's revolutionary signal system with 40+ real-world examples covering signals, linked signals, resource API, and defer blocks

🌟 View Live Demo | πŸ“– Documentation | 🀝 Contribute


🌟 What You'll Learn


Angular Signals
Modern reactive state management

Performance
Defer blocks & optimization

πŸ“‹ Table of Contents

🎯 Examples - Signals

πŸ”₯ 16 comprehensive examples showcasing Angular's reactive signal system from basics to advanced patterns

πŸ“Š Beginner Examples (1-8)
# Example Description Live Demo
1 Count Increment/Decrement Basic signal operations πŸ”— Demo
2 Auto Increment Count Automatic signal updates πŸ”— Demo
3 Update Name Using Input Input binding with signals πŸ”— Demo
4 Computed Signals Derived state management πŸ”— Demo
5 Todo List CRUD operations with signals πŸ”— Demo
6 Input with ngModel Two-way data binding πŸ”— Demo
7 Observable to Signal Migration from RxJS πŸ”— Demo
8 Signal with Side Effects Effect management πŸ”— Demo
🎨 Advanced Examples (9-16)
# Example Description Live Demo
9 Simple VAT Calculator Business logic with signals πŸ”— Demo
10 Product Search Real-time filtering πŸ”— Demo
11 Input Signals Component input patterns πŸ”— Demo
12 Untracked Signal Performance optimization πŸ”— Demo
13 Shopping Cart Complex state management πŸ”— Demo
14 Virtual Scroll Performance with large datasets πŸ”— Demo
15 Loading Spinner UI state management πŸ”— Demo
16 Read Only Signals Immutable state patterns πŸ”— Demo

πŸ”— Examples - LinkedSignal

πŸ”„ 3 powerful examples demonstrating Angular's LinkedSignal for reactive computed state

# Example Description Key Features Live Demo
1 Default Course Quantity Basic linked signal implementation β€’ Default values
β€’ Reactive updates
πŸ”— Demo
2 Total Price Calculator Dynamic price calculations β€’ Mathematical operations
β€’ Real-time computation
πŸ”— Demo
3 Dynamic Pricing Engine Advanced pricing based on user & product β€’ Complex business logic
β€’ Multi-factor calculations
πŸ”— Demo
4 Unit Converter (Celsius ↔ Fahrenheit) Two-way unit conversion with linkedSignal β€’ Bi-directional binding
β€’ Real-world scenario
πŸ”— Demo

πŸ“‘ Examples - Resource API

🌐 6 comprehensive examples showcasing Angular's new Resource API for data fetching

# Example API Type Description Live Demo
1 Basic Fetch resource() Simple data fetching patterns πŸ”— Demo
2 List Resources rxResource() Working with RxJS streams πŸ”— Demo
3 HTTP Resource httpResource() HTTP client integration πŸ”— Demo
4 Random User API resource() Real-world API integration πŸ”— Demo
5 GitHub Repositories rxResource() Complex data transformations πŸ”— Demo
6 Random Jokes httpResource() Error handling & retry logic πŸ”— Demo

⏳ Examples - Defer Block

⚑ 11 performance-focused examples showcasing Angular's defer blocks for lazy loading optimization

Defer Block

Angular's defer blocks provide declarative lazy loading for better performance by deferring the loading of parts of your template until specific conditions are met.

πŸ”° Basic Defer Triggers

# Example Trigger Type Description Live Demo
1 Defer on Idle @idle Loads when browser becomes idle πŸ”— Demo
2 Defer on Interaction @interaction Triggers on user interaction πŸ”— Demo
3 Defer on Viewport @viewport Loads when entering viewport πŸ”— Demo
4 Defer with Timer @timer Time-based loading πŸ”— Demo
6 Defer on Hover @hover Mouse hover triggers πŸ”— Demo
7 Defer on Immediate @immediate Immediate after render πŸ”— Demo

🎯 Advanced Defer Patterns

# Example Advanced Features Description Live Demo
5 Advanced Defer Multiple triggers + Error handling Complex condition management πŸ”— Demo
8 Multiple Triggers & Prefetch Performance optimization Smart prefetching strategies πŸ”— Demo
9 Error Handling & Retry Robust error management Retry mechanisms & fallbacks πŸ”— Demo
10 Loading States with Timing Professional UX Anti-flicker timing controls πŸ”— Demo
11 Real-world Dashboard Production-ready Complete dashboard widget πŸ”— Demo

πŸ› οΈ Development

πŸ“‹ Prerequisites

Requirement Version Description
Node.js v20+ JavaScript runtime
Angular CLI v20+ Angular development toolkit
TypeScript v5.0+ Type-safe JavaScript
Knowledge Basic Angular & TypeScript fundamentals

πŸš€ Quick Commands

# Development server
npm run start          # Start dev server (http://localhost:4200)

# Building
npm run build          # Production build
npm run build:dev      # Development build

# Testing
npm run test           # Unit tests
npm run e2e            # End-to-end tests

# Code quality
npm run lint           # ESLint
npm run format         # Prettier
πŸ“ Detailed Development Guide

Development Server

Run ng serve for a dev server. Navigate to http://localhost:4200/. The application will automatically reload if you change any of the source files.

Code Scaffolding

Run ng generate component component-name to generate a new component. You can also use ng generate directive|pipe|service|class|guard|interface|enum|module.

Build

Run ng build to build the project. The build artifacts will be stored in the dist/ directory.

Running Unit Tests

Run ng test to execute the unit tests via Karma.

Running End-to-End Tests

Run ng e2e to execute the end-to-end tests via a platform of your choice.

🀝 Contributing

We welcome contributions! Here's how you can help:


Issues
Report bugs or suggest features

Pull Requests
Submit code improvements

Documentation
Improve examples & guides

Examples
Add new signal patterns

πŸ“‹ Contribution Guidelines

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ“„ License

This project is released into the Public Domain. You can use it anywhere, for any purpose, without any restrictions whatsoever.

No rights reserved. Feel free to:

  • βœ… Use commercially
  • βœ… Modify freely
  • βœ… Distribute without attribution
  • βœ… Create derivative works
  • βœ… Use in proprietary software

This is educational content meant to help the Angular community learn and grow! πŸš€


🌟 Show Your Support

If this project helped you, please consider giving it a ⭐!

⬆ Back to Top

Made with ❀️ by Sonu Sindhu

About

This repo is to explains Angular signals and real time examples how to create and update signals, use effects, convert from observable and create computed values. It includes the angular signal demo with multiple scenario...

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •