MPT Practical List
MPT Practical List
Practical Index
Sr.
No. Practical Date
1 Create first application to print Hello World message 14-03-2024
using Angular framework.
Practical
Practical – 1
Aim: Create first application to print Hello World message
using Angular framework.
app.component.htmlfile:
<div>
<divclass="center-screen">
<h1>{{text1}}</h1>
</div>
<divclass="center-screen">
<h2>{{text2}}</h2>
</div>
<divclass="center-screen">
<h2>{{text3}}</h2>
</div>
</div>
app.component.tsfile
app.module.ts file:
Output :
Practical – 2
Aim: Design a webpage to utilize property binding and event binding
concepts using button and textbox controls.
1. ng New Practical-2
2. Open the directory of Practical-2 and search for the src/app directory in the
directory.
3. Write the following code in the app.component.ts file create Practical- 2
src/app directory.
app.component.ts file:
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
app.component.html file:
app.module.ts file:
declarations: [ AppComponent],
imports: [ BrowserModule, FormsModule ],
providers: [],
bootstrap: [AppComponent]
})
Output :
Practical – 3
Aim: Design a web page to display student grading systems in tabular format
with alternate color style.
app.component.html file:
<table border="1">
<thead>
<tr>
<th>Student Name</th>
<th>Maths</th>
<th>Science</th>
<th>English</th>
<th>Total</th>
<th>Grade</th>
</tr>
</thead>
<body>
<tr *ngFor="let student of students; let i = index" [ngStyle]="{ 'background-color': i % 2 === 0 ?
'coral' : 'lightgray' }">
<span *ngSwitchCase="'A+'">A+</span>
<span *ngSwitchCase="'A'">A</span>
<span *ngSwitchCase="'B'">B</span>
<span *ngSwitchCase="'C'">C</span>
<span *ngSwitchDefault>No Grade</span>
</td>
</tr>
</body>
</table>
</div>
</div>
</div>
app.component.ts file:
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
maths: 65,
science: 70,
english: 80,
total: 215, grade: 'C'
}
];
}
app.module.ts file:
Output :
Practical – 4
Aim: Design component to perform following tasks
A) To add or Remove number of students using textbox and button
controls and display it in tabular structure format.
B) Give row level remove button option to student table and record
should be deleted when click on it.
student-component.html file:
<div class="solid">
<div class='panel panel-primary'>
<div class='panel-heading'>
<h3>{{title}}</h3>
</div>
<div class='panel-body'>
<div>
<input type="number" [(ngModel)]="studentCount" min="0" value="0">
<br /><br />
<table>
<thead>
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Age</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let student of students; let i=index;">
student-component.component.ts file:
@Component({
selector: 'app-student-component',
templateUrl: './student-component.component.html',
styleUrls: ['./student-component.component.css']
})
ngOnInit() { console.log("init")
this.students.push(new Student("Shweta","Patel", 21));
this.students.push(new Student("Neha","Patel", 20));
this.students.push(new Student("Ami","Patel", 22));
this.studentCount = this.students.length;
}
updateTable() {
const currentCount = this.students.length;
if (this.studentCount > currentCount) {
for (let i = currentCount; i < this.studentCount; i++) {
this.students.push(new Student('', '', 0));
}
}
else if (this.studentCount < currentCount) {
this.students.splice(this.studentCount);
}
Prof. Rinkal Umaraniya – Assi. Professor, SLTIET, Rajkot |11
Shri Labhubhai Trivedi Institute of Engineering & Technology
Department of Computer Engineering (Diploma)
Semester – 4th
Subject Name– MPT(4340705)
removeStudent(index: number) {
this.students.splice(index, 1);
}
}
class Student {
constructor(public fname: string, public lname: string, public age: number) { }
}
table {
border-collapse: collapse;
width: 100%;
}
th, td {
border: 1px solid #ddd;
padding: 8px;
text-align: left;
}
th {
background-color: #f2f2f2;
}
input[type="number"], input[type="text"] {
width: 100%;
}
.center-screen {
display: flex;
justify-content: center;
align-items: center;
text-align: center;
}
div.solid {
border-style: solid;
padding: 15px;
}
app.module.ts file:
@NgModule({
declarations: [ AppComponent, StudentComponentComponent ],
imports: [ BrowserModule, FormsModule ],
providers: [],
bootstrap: [AppComponent]
})
Output:
Practical – 5
Aim: Create a component to display a products list from array. The product
component should display a product Id, name, purchase date, price, and
image for the product and search using various pipes.
filter.pipe.ts file:
@Pipe({
name: 'filter'
})
product-list.component.css file:
table {
border-collapse: collapse; width: 100%;
}
th, td {
border: 1px solid #ddd;
padding: 8px;
text-align: left;
}
Prof. Rinkal Umaraniya – Assi. Professor, SLTIET, Rajkot |14
Shri Labhubhai Trivedi Institute of Engineering & Technology
Department of Computer Engineering (Diploma)
Semester – 4th
Subject Name– MPT(4340705)
th {
background-color: #f2f2f2;
}
input[type="text"] {
border: 2px solid blue;
border-radius: 4px;
padding: 12px;
margin-bottom: 10px;
margin-right: 10px;
}
input[type="number"], input[type="text"] {
width: 98%;
}
.center-screen {
display: flex;
justify-content: center;
align-items: center;
text-align: center;
}
div.solid {
border-style: solid;
padding: 15px;
}
product-list.component.ts file:
@Component({
selector: 'app-product-list',
templateUrl: './product-list.component.html',
styleUrls: ['./product-list.component.css']
})
{ id: 2, name: 'Stainless steel water bottle', purchaseDate: new Date('2022-02- 01'),
price: 20.99, imageUrl: 'https://thumbs.dreamstime.com/z/metal-water- bottle-reusable-
stainless-steel-flask-metal-water-bottle-reusable-stainless-steel- eco-flask-mockup-empty-
aluminum-187861207.jpg' },
Product-list.component.html file:
<div class="solid">
<div class='panel panel-primary'>
<div class='panel-heading'>
<h3>{{title}}</h3>
</div>
<br />
<div class='panel-body'>
<div class='table-responsive'>
<tbody>
<tr *ngFor="let product of products | filter: searchText">
<td>{{ product.id }}</td>
<td>{{ product.name | uppercase}}</td>
<td>{{ product.purchaseDate | date }}</td>
<td>{{ product.price | currency }}</td>
<td><img [src]="product.imageUrl" height="100" width="100"></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
app.module.ts file:
@NgModule({
declarations: [ AppComponent, ProductListComponent, FilterPipe ],
imports: [ BrowserModule, FormsModule],
providers: [],
bootstrap: [AppComponent]
})
Output:
Practical – 6
Aim: Create a program to display a color list.
Output:
Practical – 7
Aim: Create a program to age eligibility using if else loop.
Output:
Practical – 8
Aim: Write a program to print textbox value given by user.
Output:
Practical – 9
Aim: Write a program to print textbox value given by user with static
message.
Output:
Practical – 10
Prof. Rinkal Umaraniya – Assi. Professor, SLTIET, Rajkot |27
Shri Labhubhai Trivedi Institute of Engineering & Technology
Department of Computer Engineering (Diploma)
Semester – 4th
Subject Name– MPT(4340705)
Aim: Write a program to print value of button when we click the button.
Output:
Prof. Rinkal Umaraniya – Assi. Professor, SLTIET, Rajkot |28
Shri Labhubhai Trivedi Institute of Engineering & Technology
Department of Computer Engineering (Diploma)
Semester – 4th
Subject Name– MPT(4340705)