Fullstack Slip Answer
Fullstack Slip Answer
Q.1) Write an AngularJS script for addition of two numbers using ng-init, ng-model & ng-bind. And also
demonstrate ng-show, ng-disabled, ng-click directives on button component.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.8.2/angular.min.js"></script>
</head>
<br>
<br><br>
<!-- Button with ng-click to trigger addition, ng-disabled if inputs are empty -->
<!-- Display result only when showResult is true using ng-show -->
<h3 ng-show="showResult">Result: <span ng-bind="result"></span></h3>
<script>
angular.module('additionApp', [])
.controller('AdditionController', function($scope) {
$scope.addNumbers = function() {
$scope.showResult = true;
};
});
</script>
</body>
</html>
Q.2) Create a Node.js application that reads data from multiple files asynchronously using promises and
async/await.
const fs = require('fs').promises;
try {
} catch (error) {
readFiles(files);
SLIP2
Write an AngularJS script to print details of bank (bank name, MICR code, IFC code, address etc.) in
tabular form using ng-repeat.
//html file
<!DOCTYPE html>
<html ng-app="bankApp">
<head>
<title>Bank Details</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.8.2/angular.min.js"></script>
<script src="app.js"></script>
</head>
<body ng-controller="BankController">
<h2>Bank Details</h2>
<table border="1">
<thead>
<tr>
<th>Bank Name</th>
<th>MICR Code</th>
<th>IFSC Code</th>
<th>Address</th>
</tr>
</thead>
<tbody>
</tr>
</tbody>
</table>
</body>
</html>
//angularJs file
// Define controller
app.controller('BankController', function($scope) {
// List of banks
$scope.banks = [
{
name: 'Bank of America',
micrCode: '123456789',
ifscCode: 'BOFA12345',
},
micrCode: '987654321',
ifscCode: 'WF123456',
},
micrCode: '543216789',
ifscCode: 'CHAS09876',
];
});
Create a simple Angular application that fetches data from an API using HttpClient.
Implement an Observable to fetch data from an API endpoint.
// src/app/data.service.ts
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
@Injectable({
providedIn: 'root'
})
export class DataService {
private apiUrl = 'https://jsonplaceholder.typicode.com/posts'; // Sample API
<!DOCTYPE html>
<html ng-app="gameApp">
<head>
<title>Game List Display</title>
<script
src="https://ajax.googleapis.com/ajax/libs/angularjs/1.8.2/angular.min.js"></script>
</head>
<body ng-controller="GameController" ng-init="isListVisible=false">
<h1>Game List</h1>
<script>
// Define the AngularJS application module
angular.module('gameApp', [])
.controller('GameController', function($scope) {
// Initialize the list of games
$scope.games = ['Chess', 'Monopoly', 'Scrabble', 'Risk'];
Find a company with a workforce greater than 30 in the array (use find by id
method)
type Company = {
id: number;
name: string;
workforce: number;
};
console.log(companyWithLargeWorkforce);
SLIP 4
Fetch the details using ng-repeat in AngularJS
$scope.filterByWorkforce = function(company) {
return company.workforce > 30;
};
});
Express.js application to include middleware for parsing request bodies (e.g., JSON, form data) and
validating input data.
SLIP5
Create a simple Angular component that takes input data and displays it.
@Component({
selector: 'app-display-item',
templateUrl: './display-item.component.html',
styleUrls: ['./display-item.component.css']
})
export class DisplayItemComponent {
@Input() item: string = ''; // Input property to accept data from
parent
}
<div *ngIf="item">
<p>{{ item }}</p>
</div>
<app-display-item [item]="'Hello, Angular!'"></app-display-item>
SLIP 6
Develop an Express.js application that defines routes for Create and Read operations on a resource
(products).
// Basic validation
if (!name || !price) {
return res.status(400).json({ message: 'Name and price are
required' });
}
const newProduct = {
id: products.length + 1, // Simple auto-increment logic
name,
price,
};
products.push(newProduct);
res.status(201).json(newProduct); // Send the new product as
response
});
if (!product) {
return res.status(404).json({ message: 'Product not found' });
}
const companies = [
];
// Use the `find` method to locate the company with the given id and workforce > 30
if (company) {
} else {
console.log('No company found with the specified id and workforce greater than 30.');
SLIP7
Create a Node.js application that reads data from multiple files asynchronously using promises and
async/await.
const files = [
];
try {
return content;
}));
console.log(content);
console.log('---');
});
} catch (error) {
readFiles();
Develop an Express.js application that defines routes for Create and Read operations on a resource
(User).
app.use(express.json());
let users = [
];
// Basic validation
if (!name || !email) {
const newUser = {
name,
email,
};
users.push(newUser);
// Respond with the newly created user
res.status(201).json(newUser);
});
});
if (!user) {
});
app.listen(PORT, () => {
});
SLIP 8
Create a simple Angular application that fetches data from an API using HttpClient. Implement an
Observable to fetch data from an API endpoint.
@NgModule({
declarations: [AppComponent],
imports: [
BrowserModule,
],
providers: [],
bootstrap: [AppComponent]
})
@Injectable({
providedIn: 'root'
})
getPosts(): Observable<any[]> {
return this.http.get<any[]>(this.apiUrl);
Develop an Express.js application that defines routes for Create, Update operations on a resource
(Employee).
app.use(bodyParser.json());
}
// Check if employee with the given ID already exists
if (existingEmployee) {
employees.push(newEmployee);
res.status(201).json(newEmployee);
});
const { id } = req.params;
employees[employeeIndex] = {
id,
res.json(employees[employeeIndex]);
});
app.listen(port, () => {
});
SLIP 9
Find a company with a workforce greater than 30 in the array. (Using find by id method).
interface Company {
id: number;
name: string;
workforce: number;
}
if (companyWithLargeWorkforce) {
console.log(`Company with workforce greater than 30:
${companyWithLargeWorkforce.name}`);
} else {
console.log('No company with workforce greater than 30 was
found.');
}
) Create Express.js application to include middleware for parsing request bodies (e.g., JSON, form data)
and validating input data. Send appropriate JSON responses for success and error cases.
// Start the server and listen on the specified host and port
server.listen(port, host, () => {
console.log(`Server running at http://${host}:${port}/`);
});
Extend the previous Express.js application to include middleware for parsing request bodies (e.g., JSON,
form data) and validating input data. Send appropriate JSON responses for success and error cases.
SLIP11
Develop an Express.js application that defines routes for Create operations on a resource (Movie).
Create Angular application that print the name of students who play basketball using filter and map
method.
@Component({
selector: 'app-basketball',
templateUrl: './basketball.component.html',
styleUrls: ['./basketball.component.css']
})
export class BasketballComponent implements OnInit {
students = [
{ name: 'John', playsBasketball: true },
{ name: 'Jane', playsBasketball: false },
{ name: 'Tom', playsBasketball: true },
{ name: 'Lucy', playsBasketball: false },
{ name: 'Alex', playsBasketball: true }
];
constructor() { }
ngOnInit(): void {
this.filterAndMapBasketballPlayers();
}
filterAndMapBasketballPlayers() {
this.basketballPlayers = this.students
.filter(student => student.playsBasketball) // Filters students who
play basketball
.map(student => student.name); // Maps to an array of names of
those students
}
}
<div>
<h2>Students Who Play Basketball</h2>
<ul>
<li *ngFor="let player of basketballPlayers">{{ player }}</li>
</ul>
</div>
SLIP12
Write an AngularJS script to print details of Employee (employee name, employee Id,Pin code, address
etc.) in tabular form using ng-repeat.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Employee Details</title>
<script
src="https://ajax.googleapis.com/ajax/libs/angularjs/1.8.2/angular.m
in.js"></script>
</head>
<body ng-app="employeeApp" ng-controller="EmployeeController">
<h1>Employee Details</h1>
<table border="1">
<thead>
<tr>
<th>Employee Name</th>
<th>Employee ID</th>
<th>Pin Code</th>
<th>Address</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="employee in employees">
<td>{{ employee.name }}</td>
<td>{{ employee.id }}</td>
<td>{{ employee.pinCode }}</td>
<td>{{ employee.address }}</td>
</tr>
</tbody>
</table>
</body>
</html>
// Define the AngularJS module and controller
angular.module('employeeApp', [])
.controller('EmployeeController', function($scope) {
// Define the list of employee details
$scope.employees = [
{ name: 'John Doe', id: 'E001', pinCode: '12345', address: '1234 Elm
Street' },
{ name: 'Jane Smith', id: 'E002', pinCode: '67890', address: '5678
Oak Avenue' },
{ name: 'Mark Johnson', id: 'E003', pinCode: '11223', address: '9101
Pine Road' },
{ name: 'Sarah Williams', id: 'E004', pinCode: '44556', address:
'1112 Maple Lane' }
];
});
Develop an Express.js application that defines routes for Create operations on a resource (User).
// app.js
const express = require('express');
const bodyParser = require('body-parser');
SLIP13
Extend the previous Express.js application to include middleware for parsing request bodies (e.g., JSON,
form data) and validating input data. Send appropriate JSON responses for success and error cases.
if (error) {
// If validation fails, return an error response with details
return res.status(400).json({
success: false,
message: 'Validation error',
details: error.details.map(detail => detail.message),
});
}
// Default route
app.get('/', (req, res) => {
res.send('Welcome to the Express.js app!');
});
// Start server
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
console.log(`Server running on port ${PORT}`);
});
Create a simple Angular component that takes input data and displays it.
@Component({
selector: 'app-display-data',
templateUrl: './display-data.component.html',
styleUrls: ['./display-data.component.css']
})
export class DisplayDataComponent {
@Input() data: string = ''; // Input property to accept data
<div>
<p>Data received: {{ data }}</p>
</div>}
SLIP 14
Create Angular application that print the name of students who got 85% using filter and map method.
ngOnInit(): void {
// Filter students who scored 85% or more and map to their names
this.filteredStudentNames = this.students
.filter(student => student.score >= 85) // Filter students by score
.map(student => student.name); // Map the filtered students
to their names
}
}
Develop an Express.js application that defines routes for Create, Update operations on a resource
(Employee).
// Create an employee
app.post('/employees', (req, res) => {
const { name, position } = req.body;
// Validate the request body
if (!name || !position) {
return res.status(400).json({ error: 'Name and position are
required.' });
}
const newEmployee = {
id: employees.length + 1,
name,
position
};
employees.push(newEmployee);
res.status(201).json(newEmployee);
});
// Update an employee
app.put('/employees/:id', (req, res) => {
const employeeId = parseInt(req.params.id);
const { name, position } = req.body;
if (!employee) {
return res.status(404).json({ error: 'Employee not found.' });
}
res.json(employee);
});
SLIP 15
Find an emp with a Salary greater than 25000 in the array. (Using find by id method)
const employees = [
{ id: 1, name: 'John', salary: 30000 },
{ id: 2, name: 'Jane', salary: 22000 },
{ id: 3, name: 'Alice', salary: 28000 },
{ id: 4, name: 'Bob', salary: 26000 }
];
if (employee) {
console.log(`Employee found: ${employee.name}, Salary:
${employee.salary}`);
} else {
console.log('No employee found with salary greater than 25000');
}
Create Angular application that print the name of students who got 85% using filter and map method.
@Component({
selector: 'app-student-list',
templateUrl: './student-list.component.html',
styleUrls: ['./student-list.component.css']
})
export class StudentListComponent implements OnInit {
students = [
{ name: 'John Doe', score: 90 },
{ name: 'Jane Smith', score: 80 },
{ name: 'Bob Brown', score: 85 },
{ name: 'Alice Johnson', score: 95 },
{ name: 'Charlie Lee', score: 70 }
];
ngOnInit(): void {
// Filter the students who scored 85% or more, then map to get
their names.
this.studentsWith85Percent = this.students
.filter(student => student.score >= 85) // Filters students with
score 85% or more
.map(student => student.name); // Maps to just the names
}
}
<div>
<h2>Students with 85% or more:</h2>
<ul>
<li *ngFor="let student of studentsWith85Percent">{{ student
}}</li>
</ul>
</div>
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import { StudentListComponent } from './student-list/student-
list.component';
@NgModule({
declarations: [
AppComponent,
StudentListComponent
],
imports: [
BrowserModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }