From 15fc491d9a6b68ed534dbd4ee9f7b827c1ab2e98 Mon Sep 17 00:00:00 2001 From: rupeshbangar Date: Wed, 11 Mar 2026 16:12:05 +0530 Subject: [PATCH] Intro. of Angular Routing and Forms --- Week-04/Day_03/README.md | 64 ++++++++++++++++++++++++++++++++++++ Week-04/Day_04/README.md | 70 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 134 insertions(+) create mode 100644 Week-04/Day_03/README.md create mode 100644 Week-04/Day_04/README.md diff --git a/Week-04/Day_03/README.md b/Week-04/Day_03/README.md new file mode 100644 index 0000000..ee5651f --- /dev/null +++ b/Week-04/Day_03/README.md @@ -0,0 +1,64 @@ +# Angular Routing + +## Overview +Angular Routing allows navigation between different components in a Single Page Application (SPA) without reloading the page. + +It maps URL paths to components and dynamically loads them inside the application. + +--- + +## Key Concepts + +### Routes +Routes define the relationship between a URL path and a component. + +Example: + +const routes: Routes = [ + { path: 'home', component: HomeComponent }, + { path: 'about', component: AboutComponent } +]; + +--- + +### Router Outlet +`` is a directive that acts as a placeholder where routed components are displayed. + +Example: + + + +--- + +### RouterLink +Used in HTML to navigate between routes. + +Example: + +Home +About + +--- + +### Programmatic Navigation +You can navigate using the Router service. + +Example: + +constructor(private router: Router) {} + +goHome() { + this.router.navigate(['/home']); +} + +--- + +## Steps to Implement Routing + +1. Install Angular Router (included in Angular CLI projects) +2. Define routes in a routes file +3. Import RouterModule +4. Use `` in the main template +5. Add navigation links using `routerLink` + +--- \ No newline at end of file diff --git a/Week-04/Day_04/README.md b/Week-04/Day_04/README.md new file mode 100644 index 0000000..a87ef50 --- /dev/null +++ b/Week-04/Day_04/README.md @@ -0,0 +1,70 @@ +# Angular Forms + +## Overview +Angular Forms are used to capture user input and validate data in web applications. + +Angular provides two types of forms: +- Template-driven forms +- Reactive forms + +--- + +## Template-Driven Forms + +Template-driven forms rely mainly on HTML templates and Angular directives. + +Example: + +
+ + +
+ +Features: +- Easy to use +- Suitable for simple forms +- Uses `ngModel` directive + +--- + +## Reactive Forms + +Reactive forms are defined in TypeScript using FormControl and FormGroup. + +Example: + +import { FormGroup, FormControl } from '@angular/forms'; + +profileForm = new FormGroup({ + name: new FormControl(''), + email: new FormControl('') +}); + +HTML: + +
+ + +
+ +Features: +- More control +- Better for complex forms +- Easy validation and testing + +--- + +## Form Validation + +Angular provides built-in validation such as: + +- required +- minlength +- maxlength +- pattern + +Example: + + + +--- \ No newline at end of file