Angular Routing & Forms based Demo application
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
import { provideRouter } from '@angular/router';
|
||||
import { routes } from './app.routes';
|
||||
|
||||
export const appConfig = {
|
||||
providers: [provideRouter(routes)]
|
||||
};
|
||||
0
Week-04/Day_05/student-routing-form/src/app/app.css
Normal file
0
Week-04/Day_05/student-routing-form/src/app/app.css
Normal file
10
Week-04/Day_05/student-routing-form/src/app/app.html
Normal file
10
Week-04/Day_05/student-routing-form/src/app/app.html
Normal file
@@ -0,0 +1,10 @@
|
||||
<h1>Student Portal</h1>
|
||||
|
||||
<nav>
|
||||
<a routerLink="/">Home</a> |
|
||||
<a routerLink="/register">Register</a>
|
||||
</nav>
|
||||
|
||||
<hr>
|
||||
|
||||
<router-outlet></router-outlet>
|
||||
11
Week-04/Day_05/student-routing-form/src/app/app.routes.ts
Normal file
11
Week-04/Day_05/student-routing-form/src/app/app.routes.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { Routes } from '@angular/router';
|
||||
import { Home } from './home/home';
|
||||
import { RegisterComponent } from './register/register';
|
||||
|
||||
export const routes: Routes = [
|
||||
|
||||
{ path: '', component: Home },
|
||||
|
||||
{ path: 'register', component: RegisterComponent }
|
||||
|
||||
];
|
||||
23
Week-04/Day_05/student-routing-form/src/app/app.spec.ts
Normal file
23
Week-04/Day_05/student-routing-form/src/app/app.spec.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
import { App } from './app';
|
||||
|
||||
describe('App', () => {
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
imports: [App],
|
||||
}).compileComponents();
|
||||
});
|
||||
|
||||
it('should create the app', () => {
|
||||
const fixture = TestBed.createComponent(App);
|
||||
const app = fixture.componentInstance;
|
||||
expect(app).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should render title', async () => {
|
||||
const fixture = TestBed.createComponent(App);
|
||||
await fixture.whenStable();
|
||||
const compiled = fixture.nativeElement as HTMLElement;
|
||||
expect(compiled.querySelector('h1')?.textContent).toContain('Hello, student-routing-form');
|
||||
});
|
||||
});
|
||||
12
Week-04/Day_05/student-routing-form/src/app/app.ts
Normal file
12
Week-04/Day_05/student-routing-form/src/app/app.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { Component } from '@angular/core';
|
||||
import { RouterModule } from '@angular/router';
|
||||
import { CommonModule } from '@angular/common';
|
||||
|
||||
@Component({
|
||||
selector: 'app-root',
|
||||
standalone: true,
|
||||
imports: [CommonModule, RouterModule],
|
||||
templateUrl: './app.html',
|
||||
styleUrls: ['./app.css']
|
||||
})
|
||||
export class AppComponent {}
|
||||
@@ -0,0 +1,9 @@
|
||||
h2{
|
||||
text-align:center;
|
||||
color:#2c3e50;
|
||||
}
|
||||
|
||||
p{
|
||||
text-align:center;
|
||||
font-size:18px;
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
<h2>Welcome to Student Portal</h2>
|
||||
|
||||
<p>
|
||||
This is the home page of the application.
|
||||
Click Register to fill the student form.
|
||||
</p>
|
||||
@@ -0,0 +1,22 @@
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { Home } from './home';
|
||||
|
||||
describe('Home', () => {
|
||||
let component: Home;
|
||||
let fixture: ComponentFixture<Home>;
|
||||
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
imports: [Home],
|
||||
}).compileComponents();
|
||||
|
||||
fixture = TestBed.createComponent(Home);
|
||||
component = fixture.componentInstance;
|
||||
await fixture.whenStable();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
11
Week-04/Day_05/student-routing-form/src/app/home/home.ts
Normal file
11
Week-04/Day_05/student-routing-form/src/app/home/home.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { Component } from '@angular/core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
|
||||
@Component({
|
||||
selector: 'app-home',
|
||||
standalone: true,
|
||||
imports: [CommonModule],
|
||||
templateUrl: './home.html',
|
||||
styleUrls: ['./home.css'],
|
||||
})
|
||||
export class Home {}
|
||||
@@ -0,0 +1,46 @@
|
||||
h2{
|
||||
text-align:center;
|
||||
color :#2c3e50;
|
||||
}
|
||||
|
||||
form{
|
||||
width:350px;
|
||||
margin:auto;
|
||||
padding:20px;
|
||||
background:white;
|
||||
border-radius:8px;
|
||||
box-shadow:0 0 10px rgba(0,0,0,0.1);
|
||||
}
|
||||
|
||||
label{
|
||||
font-weight:bold;
|
||||
}
|
||||
|
||||
input{
|
||||
width:100%;
|
||||
padding:8px;
|
||||
margin-top:5px;
|
||||
border:1px solid #ccc;
|
||||
border-radius:4px;
|
||||
}
|
||||
|
||||
button{
|
||||
margin-top:15px;
|
||||
width:100%;
|
||||
padding:10px;
|
||||
background:#3498db;
|
||||
color:white;
|
||||
border:none;
|
||||
border-radius:4px;
|
||||
cursor:pointer;
|
||||
}
|
||||
|
||||
button:hover{
|
||||
background:#2980b9;
|
||||
}
|
||||
|
||||
.error{
|
||||
color:red;
|
||||
font-size:13px;
|
||||
margin-top:5px;
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
<h2>Student Registration Form</h2>
|
||||
|
||||
<form #studentForm="ngForm" (ngSubmit)="onSubmit(studentForm)">
|
||||
|
||||
<!-- Name -->
|
||||
<label>Name:</label>
|
||||
<input type="text" name="name" ngModel required #name="ngModel">
|
||||
|
||||
<div class="error" *ngIf="name.invalid && name.touched">
|
||||
Name is required
|
||||
</div>
|
||||
|
||||
<br><br>
|
||||
|
||||
<!-- Email -->
|
||||
<label>Email:</label>
|
||||
<input type="email"
|
||||
name="email"
|
||||
ngModel
|
||||
required
|
||||
email
|
||||
#email="ngModel">
|
||||
|
||||
<div class="error" *ngIf="email.invalid && email.touched">
|
||||
|
||||
<div *ngIf="email.errors?.['required']">
|
||||
Email is required
|
||||
</div>
|
||||
|
||||
<div *ngIf="email.errors?.['email']">
|
||||
Enter valid email (must include @)
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<br><br>
|
||||
|
||||
<!-- Password -->
|
||||
<label>Password:</label>
|
||||
<input type="password"
|
||||
name="password"
|
||||
ngModel
|
||||
required
|
||||
minlength="8"
|
||||
#password="ngModel">
|
||||
|
||||
<div class="error" *ngIf="password.invalid && password.touched">
|
||||
|
||||
<div *ngIf="password.errors?.['required']">
|
||||
Password is required
|
||||
</div>
|
||||
|
||||
<div *ngIf="password.errors?.['minlength']">
|
||||
Password must be at least 8 characters
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<br><br>
|
||||
|
||||
<!-- Course -->
|
||||
<label>Course:</label>
|
||||
<input type="text" name="course" ngModel required #course="ngModel">
|
||||
|
||||
<div class="error" *ngIf="course.invalid && course.touched">
|
||||
Course is required
|
||||
</div>
|
||||
|
||||
<br><br>
|
||||
|
||||
<button type="submit" [disabled]="studentForm.invalid">
|
||||
Submit
|
||||
</button>
|
||||
|
||||
</form>
|
||||
@@ -0,0 +1,22 @@
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { Register } from './register';
|
||||
|
||||
describe('Register', () => {
|
||||
let component: Register;
|
||||
let fixture: ComponentFixture<Register>;
|
||||
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
imports: [Register],
|
||||
}).compileComponents();
|
||||
|
||||
fixture = TestBed.createComponent(Register);
|
||||
component = fixture.componentInstance;
|
||||
await fixture.whenStable();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,25 @@
|
||||
import { Component } from '@angular/core';
|
||||
import { FormsModule, NgForm } from '@angular/forms';
|
||||
import { CommonModule } from '@angular/common';
|
||||
|
||||
@Component({
|
||||
selector: 'app-register',
|
||||
standalone: true,
|
||||
imports: [FormsModule, CommonModule],
|
||||
templateUrl: './register.html',
|
||||
styleUrl: './register.css'
|
||||
})
|
||||
export class RegisterComponent {
|
||||
|
||||
onSubmit(form: NgForm) {
|
||||
|
||||
console.log(form.value);
|
||||
|
||||
alert("Form Submitted Successfully!");
|
||||
|
||||
// reset form
|
||||
form.reset();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
13
Week-04/Day_05/student-routing-form/src/index.html
Normal file
13
Week-04/Day_05/student-routing-form/src/index.html
Normal file
@@ -0,0 +1,13 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>StudentRoutingForm</title>
|
||||
<base href="/">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<link rel="icon" type="image/x-icon" href="favicon.ico">
|
||||
</head>
|
||||
<body>
|
||||
<app-root></app-root>
|
||||
</body>
|
||||
</html>
|
||||
6
Week-04/Day_05/student-routing-form/src/main.ts
Normal file
6
Week-04/Day_05/student-routing-form/src/main.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
import { bootstrapApplication } from '@angular/platform-browser';
|
||||
import { appConfig } from './app/app.config';
|
||||
import { AppComponent } from './app/app';
|
||||
|
||||
bootstrapApplication(AppComponent, appConfig)
|
||||
.catch((err) => console.error(err));
|
||||
33
Week-04/Day_05/student-routing-form/src/styles.css
Normal file
33
Week-04/Day_05/student-routing-form/src/styles.css
Normal file
@@ -0,0 +1,33 @@
|
||||
body{
|
||||
font-family: Arial, Helvetica, sans-serif;
|
||||
margin:0;
|
||||
padding:0;
|
||||
background:#f4f6f8;
|
||||
}
|
||||
|
||||
h1{
|
||||
text-align:center;
|
||||
background:#2c3e50;
|
||||
color:white;
|
||||
padding:15px;
|
||||
}
|
||||
|
||||
nav{
|
||||
text-align:center;
|
||||
margin:20px;
|
||||
}
|
||||
|
||||
nav a{
|
||||
text-decoration:none;
|
||||
color:#2c3e50;
|
||||
font-weight:bold;
|
||||
margin:10px;
|
||||
}
|
||||
|
||||
nav a:hover{
|
||||
color:#3498db;
|
||||
}
|
||||
|
||||
hr{
|
||||
margin:20px;
|
||||
}
|
||||
Reference in New Issue
Block a user