Introduction
Bootstrap makes a developer's life easy while developing the application with realistic UI. It is tough to set up the UI manually or ask another developer to set up the basic layout. However, by using Bootstrap, developers can set the application's basic layout Easly.
Bootstrap provides breakpoints, containers, grids, column structures, forms, content, and components. Obviously, to create a customized template or design, you need to write custom CSS code and JavaScript functions, but Bootstrap is fully flexible, and you can write your custom CSS and JS functions along with Bootstrap. Let's check out how we can add a bootstrap to the angular application.
Step 1. Create a new Angular Application using the below command.
ng new your-application-name
In this article, I have used employee shift management for demo purposes. I have used the below command to create a new angular application.
ng new employee-shift-management
Step 2. Add controls to the application page.
Add the controls or forms based on the requirements of your application. In this demo, I have used employee shift management, so I added a field called Employee name, type, shift, and shift date. Check out the sample code before adding the bootstrap classes and also preview for the same.
app.component.ts
import { Component, OnInit } from '@angular/core';
import { FormGroup, FormControl, Validators } from '@angular/forms';
import { Employee } from './Models/employee.model';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent implements OnInit {
title = 'Employee Shift Management';
employeeShiftForm!: FormGroup;
lstEmployee: Employee[] = [];
ngOnInit(): void {
this.employeeShiftForm = new FormGroup({
Name: new FormControl(null, [Validators.required]),
Type: new FormControl(null, [Validators.required]),
Shift: new FormControl(null, [Validators.required]),
ShiftDate: new FormControl(null, [Validators.required]),
});
}
onSubmit() {
// Mark all fields as touched
this.employeeShiftForm.markAllAsTouched();
if (this.employeeShiftForm.valid) {
let emp: Employee = {
Name: '',
Type: '',
Shift: '',
ShiftDate: new Date()
};
emp.Name = this.employeeShiftForm.get('Name')?.value;
emp.Type = this.employeeShiftForm.get('Type')?.value;
emp.Shift = this.employeeShiftForm.get('Shift')?.value;
emp.ShiftDate = this.employeeShiftForm.get('ShiftDate')?.value;
this.lstEmployee.push(emp);
} else {
console.log('Invalid Form values');
}
}
}
app.component.html
<html>
<head>
</head>
<header>
<h1>Employee Shift Management</h1>
</header>
<div>
<h2>Add Employee</h2>
<form [formGroup]="employeeShiftForm" (ngSubmit)="onSubmit()">
<table>
<tr>
<td>Employee Name</td>
<td>
<input type="text" name="Name" formControlName="Name">
<div *ngIf="employeeShiftForm.controls.Name.touched && employeeShiftForm.controls.Name.errors?.required">
<span>Please enter name.</span>
</div>
</td>
</tr>
<tr>
<td>Employee Type</td>
<td>
<select id="idEmpType" formControlName="Type" style="width: 100%;">
<option value="1">Manager</option>
<option value="2">Plant Head</option>
<option value="3">Supervisor</option>
<option value="4">Labour</option>
</select>
<div *ngIf="employeeShiftForm.controls.Type.touched && employeeShiftForm.controls.Type.errors?.required">
<span>Please select Type.</span>
</div>
</td>
</tr>
<tr>
<td>Employee Shift</td>
<td>
<select id="idEmpShift" formControlName="Shift" style="width: 100%;">
<option value="1">First Shift</option>
<option value="2">Second Shift</option>
<option value="3">Third Shift</option>
</select>
<div *ngIf="employeeShiftForm.controls.Shift.touched && employeeShiftForm.controls.Shift.errors?.required">
<span>Please select Shift.</span>
</div>
</td>
</tr>
<tr>
<td>Shift Date</td>
<td>
<input type="date" name="EmployeeDateOfJoin" formControlName="ShiftDate" style="width: 100%;">
<div *ngIf="employeeShiftForm.controls.ShiftDate.touched && employeeShiftForm.controls.ShiftDate.errors?.required">
<span>Please select Shift Date.</span>
</div>
</td>
</tr>
<tr>
<td colspan="2">
<input type="button" name="EmployeeDateOfJoin" value="Cancel">
<button type="submit">Submit</button>
</td>
</tr>
</table>
</form>
</div>
<div>
<h2>List of Employees</h2>
<table border="1">
<tr>
<th>No</th>
<th>Name</th>
<th>Employee Type</th>
<th>Shift</th>
<th>Date Of Join</th>
</tr>
<tr *ngFor="let employee of lstEmployee; let i = index">
<td>{{ i + 1 }}</td>
<td>{{ employee.Name }}</td>
<td>{{ employee.Type }}</td>
<td>{{ employee.Shift }}</td>
<td>{{ employee.ShiftDate }}</td>
</tr>
</table>
</div>
<footer>
<span>Footer Text!</span>
</footer>
</html>
Below is the preview without bootstrap. I only used table structure and form controls.









Jignesh KumarPosted Sep 24, 2024, 7:53 AM
Useful post
Emmmanuel FIADUFEPosted Sep 23, 2024, 9:24 PM
Thank you Mr Vishal for the tutorial