Congratulations on making it this far! You’ve learned about the most impactful new features in Angular v21. Now, it’s time to consolidate that knowledge by building a practical application. This project will integrate many of the concepts we’ve covered, giving you hands-on experience in a real-world context.
Project Goal: Simple User Management Application
We will build a basic User Management Application. This application will:
- Display a list of users.
- Allow adding new users.
- Provide basic user details.
- Be built entirely with standalone components and services.
- Leverage signals for state management wherever possible.
- Operate in a zoneless change detection environment for optimal performance.
- Utilize the HttpClient (by default) for API communication.
- Potentially integrate Signal Forms (if they progress to a more stable state, or as an experimental exercise).
Why This Project?
This project is chosen because it naturally lends itself to demonstrating:
- Zoneless Change Detection: By working with signals and
HttpClient, you’ll implicitly experience the benefits of zoneless. - Signals for State Management: Users, loading states, and error messages are perfect candidates for signals.
- HttpClient (by default): Every user management app needs to talk to a backend to fetch, add, and update users.
- Standalone Components: We’ll build modular components without
NgModules. - New Control Flow: We’ll use
@if,@for,@switchfor conditional rendering and lists.
Tools and Technologies We’ll Use
- Angular v21+: The core framework.
- Angular CLI: For scaffolding and building.
- TypeScript: For type-safe JavaScript.
- Signals: For reactive state management.
- HttpClient: For API interactions.
- (Optional) JSON Server: A simple way to set up a mock REST API locally for development, so we don’t need a real backend.
Project Setup: Initializing the Application
Let’s start by creating a new Angular v21 project.
Create a New Angular Project: Open your terminal and run:
ng new user-management-app --standalone --routing --strict cd user-management-appThis creates a new Angular v21 standalone application, which by default will be zoneless and use
esbuildfor its build process.Install JSON Server (Optional but Recommended for Backend Simulation): To simulate a backend API, we’ll use
json-server. This allows us to quickly create a REST API from a JSON file.npm install -D json-serverCreate a
db.jsonfile for your mock data: In the root of youruser-management-appproject (or in aserver/directory, for example), create a file nameddb.jsonwith some initial user data:// db.json { "users": [ { "id": 1, "name": "Alice Smith", "email": "[email protected]", "role": "admin" }, { "id": 2, "name": "Bob Johnson", "email": "[email protected]", "role": "user" }, { "id": 3, "name": "Charlie Brown", "email": "[email protected]", "role": "user" } ] }Add a script to
package.jsonto run JSON Server: Openpackage.jsonand add a new script under"scripts":// package.json (snippet) "scripts": { "ng": "ng", "start": "ng serve", "build": "ng build", "watch": "ng build --watch --configuration development", "test": "ng test", "serve:json-api": "json-server --watch db.json --port 3000" // Add this line },Now you can run your mock API with
npm run serve:json-api.Test the JSON Server: Run
npm run serve:json-apiin one terminal. Open your browser tohttp://localhost:3000/users. You should see your mock user data.
Project Structure (High-Level Plan)
Here’s how we’ll structure our application, leveraging standalone components:
src/app/app.component.ts: The root component, primarily for layout and routing.src/app/shared/: Common interfaces and perhaps a utility service.src/app/shared/models/user.interface.ts
src/app/core/: Core application services (e.g.,UserService).src/app/core/services/user.service.ts
src/app/features/users/: Feature-specific components related to user management.src/app/features/users/components/user-list/user-list.component.tssrc/app/features/users/components/user-form/user-form.component.tssrc/app/features/users/pages/users-page/users-page.component.ts(a routing host component)
Outline of Project Chapters
This project will span multiple “chapters” to guide you incrementally:
- Chapter 15.1: Defining User Model and Service: Create the
Userinterface andUserServicefor API interaction. - Chapter 15.2: Displaying User List: Implement
UserListComponentand integrate it intoUsersPageComponent. - Chapter 15.3: Adding New Users with Signal Forms: Create
UserFormComponentto add new users, leveraging Signal Forms (experimentally). - Chapter 15.4: Integrating and Routing: Set up routes for the user features and integrate the components.
- Chapter 15.5: Basic Error Handling and Loading States: Enhance the app with signals for loading and error feedback.
- Chapter 15.6: Testing Core Components and Services (with Vitest): Write unit tests for our
UserServiceandUserListComponent.
Mini-Challenge: Review app.config.ts
Before we proceed, open your new project’s src/app/app.config.ts file.
- Do you see
provideExperimentalZonelessChangeDetection()orprovideZoneChangeDetection()explicitly added? - What about
provideHttpClient()?
Reflect on what we learned about Angular v21 defaults. This exercise helps confirm your project’s foundational setup.
Summary/Key Takeaways
- The project will be a User Management Application, built with Angular v21’s modern features: standalone components, signals, zoneless change detection, and HttpClient.
- We’ve initiated the project by creating a new Angular CLI app and setting up
json-serverfor a mock backend. - The project will follow a structured approach, building features incrementally across dedicated chapters.
Get ready to apply your newfound Angular v21 knowledge and build a functional application! In the next sub-chapter, we’ll start by defining our user data model and creating the service to interact with our mock API.