Activity 23: Research Angular Services
What are Angular Services?
Angular services provide a way for you to separate Angular app data and functions that can be used by multiple components in your app. To be used by multiple components, a service must be made injectable. Services that are injectable and used by a component become dependencies of that component.
Student List – Manage a list of students.
TYPESCRIPT:
import { Component } from '@angular/core'; import { Injectable } from '@angular/core'; @Injectable({ providedIn: 'root', }) @Component({ selector: 'app-studentlist', templateUrl: './studentlist.component.html', styleUrl: './studentlist.component.css' }) export class StudentlistComponent { studentList: string[] = ["Jerome1", "Jerome2"]; item: string = ''; addItems() { this.studentList.push(this.item); } deleteStudent(index: number) { this.studentList.splice(index, 1); } }
OUTPUT:
Employee List – Manage a list of employees.
TYPESCRIPT:import { Component } from '@angular/core'; import { Injectable } from '@angular/core'; @Injectable({ providedIn: 'root', }) @Component({ selector: 'app-employeelist', templateUrl: './employeelist.component.html', styleUrl: './employeelist.component.css' }) export class EmployeelistComponent { employeeList: string[] = ["employee1", "employee2"]; item: string = ''; addItems() { this.employeeList.push(this.item); } deleteEmployee(index: number) { this.employeeList.splice(index, 1); } }
OUTPUT:
Fruit List – List different types of fruits.
TYPESCRIPT:
import { Component } from '@angular/core'; import { Injectable } from '@angular/core'; @Injectable({ providedIn: 'root', }) @Component({ selector: 'app-fruit', templateUrl: './fruit.component.html', styleUrl: './fruit.component.css' }) export class FruitComponent { fruitList: string[] = ["Apple", "Banana", "Orange"]; item: string = ''; addItems() { this.fruitList.push(this.item); } deleteFruit(index: number) { this.fruitList.splice(index, 1); } }
OUTPUT:
Course List – List of courses offered in a school.
TYPESCRIPT:
import { Component } from '@angular/core'; import { Injectable } from '@angular/core'; @Injectable({ providedIn: 'root', }) @Component({ selector: 'app-course', templateUrl: './course.component.html', styleUrl: './course.component.css' }) export class CourseComponent { courseList: string[] = ["BSIT", "COMSCI", "ACOUNTANCY"]; item: string = ''; addItems() { this.courseList.push(this.item); } deleteCourse(index: number) { this.courseList.splice(index, 1); } }
OUTPUT:
Book List – List of books in a library.
TYPESCRIPT:
import { Component } from '@angular/core'; import { Injectable } from '@angular/core'; @Injectable({ providedIn: 'root', }) @Component({ selector: 'app-book', templateUrl: './book.component.html', styleUrl: './book.component.css' }) export class BookComponent { bookList: string[] = ["The Lord of the Rings", "Pride and Prejudice", "To Kill a Mockingbird"]; item: string = ''; addItems() { this.bookList.push(this.item); } deleteBook(index: number) { this.bookList.splice(index, 1); } }
OUTPUT:
City List – List of cities a company operates in.
TYPESCRIPT:
import { Component } from '@angular/core'; import { Injectable } from '@angular/core'; @Injectable({ providedIn: 'root', }) @Component({ selector: 'app-city', templateUrl: './city.component.html', styleUrl: './city.component.css' }) export class CityComponent { cityList: string[] = ["London", "Paris", "New York"]; item: string = ''; addItems() { this.cityList.push(this.item); } deleteCity(index: number) { this.cityList.splice(index, 1); } }
OUTPUT:
Movie List – List of movies in a theater.
TYPESCRIPT:
import { Component } from '@angular/core'; import { Injectable } from '@angular/core'; @Injectable({ providedIn: 'root', }) @Component({ selector: 'app-movie', templateUrl: './movie.component.html', styleUrl: './movie.component.css' }) export class MovieComponent { movieList: string[] = ["The Shawshank Redemption", "The Godfather", "The Dark Knight"]; item: string = ''; addItems() { this.movieList.push(this.item); } deleteMovie(index: number) { this.movieList.splice(index, 1); } }
OUTPUT:
Car Model List – List of car models available at a dealership.
TYPESCRIPT:
import { Component } from '@angular/core'; import { Injectable } from '@angular/core'; @Injectable({ providedIn: 'root', }) @Component({ selector: 'app-car', templateUrl: './car.component.html', styleUrl: './car.component.css' }) export class CarComponent { carModelList: string[] = ["Toyota Camry", "Honda Civic", "Ford Mustang"]; item: string = ''; addItems() { this.carModelList.push(this.item); } deleteCarModel(index: number) { this.carModelList.splice(index, 1); } }
OUTPUT:
Product List – List of products sold in a store.
TYPESCRIPT:
import { Component } from '@angular/core'; import { Injectable } from '@angular/core'; @Injectable({ providedIn: 'root', }) @Component({ selector: 'app-product', templateUrl: './product.component.html', styleUrl: './product.component.css' }) export class ProductComponent { productList: string[] = ["Laptop", "Smartphone", "Headphones"]; item: string = ''; addItems() { this.productList.push(this.item); } deleteProduct(index: number) { this.productList.splice(index, 1); } }
OUTPUT:
Subject List – List of subjects taught in a semester.
TYPESCRIPT:
import { Component } from '@angular/core'; import { Injectable } from '@angular/core'; @Injectable({ providedIn: 'root', }) @Component({ selector: 'app-subject', templateUrl: './subject.component.html', styleUrl: './subject.component.css' }) export class SubjectComponent { subjectList: string[] = ["Mathematics", "English", "Science"]; item: string = ''; addItems() { this.subjectList.push(this.item); } deleteSubject(index: number) { this.subjectList.splice(index, 1); } }
OUTPUT:
Country List – List of countries by continent.
TYPESCRIPT:
import { Component } from '@angular/core'; import { Injectable } from '@angular/core'; @Injectable({ providedIn: 'root', }) @Component({ selector: 'app-country', templateUrl: './country.component.html', styleUrl: './country.component.css' }) export class CountryComponent { countryList: string[] = ["United States", "Canada", "Mexico"]; item: string = ''; addItems() { this.countryList.push(this.item); } deleteCountry(index: number) { this.countryList.splice(index, 1); } }
OUTPUT:
Sports List – List of popular sports.
TYPESCRIPT:
import { Component } from '@angular/core'; import { Injectable } from '@angular/core'; @Injectable({ providedIn: 'root', }) @Component({ selector: 'app-sport', templateUrl: './sport.component.html', styleUrl: './sport.component.css' }) export class SportComponent { sportsList: string[] = ["Soccer", "Basketball", "Tennis"]; item: string = ''; addItems() { this.sportsList.push(this.item); } deleteSport(index: number) { this.sportsList.splice(index, 1); } }
OUTPUT:
Vegetable List – List of vegetables available at a grocery store.
TYPESCRIPT:
import { Component } from '@angular/core'; import { Injectable } from '@angular/core'; @Injectable({ providedIn: 'root', }) @Component({ selector: 'app-vagetable', templateUrl: './vagetable.component.html', styleUrl: './vagetable.component.css' }) export class VagetableComponent { vegetableList: string[] = ["Carrot", "Broccoli", "Tomato"]; item: string = ''; addItems() { this.vegetableList.push(this.item); } deleteVegetable(index: number) { this.vegetableList.splice(index, 1); } }
OUTPUT:
Animal List – List of animals in a zoo.
TYPESCRIPT:
import { Component } from '@angular/core'; import { Injectable } from '@angular/core'; @Injectable({ providedIn: 'root', }) @Component({ selector: 'app-animal', templateUrl: './animal.component.html', styleUrl: './animal.component.css' }) export class AnimalComponent { animalList: string[] = ["Dog", "Cat", "Elephant"]; item: string = ''; addItems() { this.animalList.push(this.item); } deleteAnimal(index: number) { this.animalList.splice(index, 1); } }
OUTPUT:
Tool List – List of tools used in a workshop.
TYPESCRIPT:
import { Component } from '@angular/core'; import { Injectable } from '@angular/core'; @Injectable({ providedIn: 'root', }) @Component({ selector: 'app-tool', templateUrl: './tool.component.html', styleUrl: './tool.component.css' }) export class ToolComponent { toolList: string[] = ["Hammer", "Screwdriver", "Wrench"]; item: string = ''; addItems() { this.toolList.push(this.item); } deleteTool(index: number) { this.toolList.splice(index, 1); } }
OUTPUT:
Language List – List of programming languages.
TYPESCRIPT:
import { Component } from '@angular/core'; import { Injectable } from '@angular/core'; @Injectable({ providedIn: 'root', }) @Component({ selector: 'app-laguage', templateUrl: './laguage.component.html', styleUrl: './laguage.component.css' }) export class LaguageComponent { languageList: string[] = ["English", "Spanish", "French"]; item: string = ''; addItems() { this.languageList.push(this.item); } deleteLanguage(index: number) { this.languageList.splice(index, 1); } }
OUTPUT:
Game List – List of video games.
TYPESCRIPT:
import { Component } from '@angular/core'; import { Injectable } from '@angular/core'; @Injectable({ providedIn: 'root', }) @Component({ selector: 'app-game', templateUrl: './game.component.html', styleUrl: './game.component.css' }) export class GameComponent { gameList: string[] = ["Mario Kart", "Minecraft", "Fortnite"]; item: string = ''; addItems() { this.gameList.push(this.item); } deleteGame(index: number) { this.gameList.splice(index, 1); } }
OUTPUT:
Software List – List of software installed on a computer.
TYPESCRIPT:
import { Component } from '@angular/core'; import { Injectable } from '@angular/core'; @Injectable({ providedIn: 'root', }) @Component({ selector: 'app-software', templateUrl: './software.component.html', styleUrl: './software.component.css' }) export class SoftwareComponent { softwareList = [ { name: 'Microsoft Word', version: '2021' }, { name: 'Adobe Photoshop', version: 'CC 2022' }, { name: 'Google Chrome', version: '100' } ]; item: string = ''; addItems() { // Add a new software item to the list if (this.item.trim() !== '') { this.softwareList.push({ name: this.item, version: '' }); this.item = ''; // Clear the input field } } deleteProduct(index: number) { this.softwareList.splice(index, 1); } }
OUTPUT:
Phone Contact List – List of phone contacts.
TYPESCRIPT:
```typescript import { Component } from '@angular/core';
interface Contact { name: string; phoneNumber: string;
}import { Injectable } from '@angular/core'; @Injectable({ providedIn: 'root', }) @Component({ selector: 'app-phone', templateUrl: './phone.component.html', styleUrl: './phone.component.css' }) export class PhoneComponent { contactList: Contact[] = [ { name: "Jerome Beriso", phoneNumber: "123-456-7890" }, { name: "Je rome", phoneNumber: "987-654-3210" } ]; name: string = ''; phoneNumber: string = '';
addContact() { const newContact: Contact = { name: this.name, phoneNumber: this.phoneNumber }; this.contactList.push(newContact); this.name = ''; this.phoneNumber = ''; }
deleteContact(index: number) { this.contactList.splice(index, 1); } }
OUTPUT:

20. Music Playlist – List of songs in a playlist.
TYPESCRIPT:
```typescript
import { Component } from '@angular/core';
import { Injectable } from '@angular/core';
@Injectable({
providedIn: 'root',
})
@Component({
selector: 'app-music',
templateUrl: './music.component.html',
styleUrl: './music.component.css'
})
export class MusicComponent {
playlist: string[] = ["Bohemian Rhapsody", "Imagine", "Hotel California"];
newSong: string = '';
addSong() {
this.playlist.push(this.newSong);
this.newSong = ''; // Clear the input field
}
deleteSong(index: number) {
this.playlist.splice(index, 1);
}
}
OUTPUT:
Food Menu – List of food items on a restaurant menu.
TYPESCRIPT:
import { Component } from '@angular/core'; import {FormsModule} from "@angular/forms"; import { Injectable } from '@angular/core'; @Injectable({ providedIn: 'root', }) @Component({ selector: 'app-food', templateUrl: './food.component.html', styleUrl: './food.component.css' }) export class FoodComponent { menuItems: string[] = ["Pizza", "Pasta", "Salad", "Burger"]; newItem: string = ''; addMenuItem() { this.menuItems.push(this.newItem); this.newItem = ''; // Clear the input field } deleteMenuItem(index: number) { this.menuItems.splice(index, 1); } }
OUTPUT:
Grocery List – List of items to buy in a grocery store.
TYPESCRIPT:
import { Component } from '@angular/core'; import {FormsModule} from "@angular/forms"; import { Injectable } from '@angular/core'; @Injectable({ providedIn: 'root', }) @Component({ selector: 'app-grocery', templateUrl: './grocery.component.html', styleUrl: './grocery.component.css' }) export class GroceryComponent { groceryList: string[] = ["Milk", "Eggs", "Bread", "Cheese"]; newItem: string = ''; addItem() { this.groceryList.push(this.newItem); this.newItem = ''; // Clear the input field } deleteItem(index: number) { this.groceryList.splice(index, 1); } }
OUTPUT:
Classroom List – List of students in a classroom.
TYPESCRIPT:
import { Component } from '@angular/core'; import { Injectable } from '@angular/core'; @Injectable({ providedIn: 'root', }) @Component({ selector: 'app-classroom', templateUrl: './classroom.component.html', styleUrl: './classroom.component.css' }) export class ClassroomComponent { studentList: string[] = ["Alice", "Bob", "Charlie", "David"]; newStudent: string = ''; addStudent() { this.studentList.push(this.newStudent); this.newStudent = ''; // Clear the input field } deleteStudent(index: number) { this.studentList.splice(index, 1); } }
OUTPUT:
Inventory List – List of items in a store’s inventory.
TYPESCRIPT:
import { Component } from '@angular/core'; interface InventoryItem { name: string; quantity: number; }import { Injectable } from '@angular/core'; @Injectable({ providedIn: 'root', }) @Component({ selector: 'app-inventory', templateUrl: './inventory.component.html', styleUrl: './inventory.component.css' }) export class InventoryComponent { inventory: InventoryItem[] = [ { name: "T-Shirt", quantity: 20 }, { name: "Jeans", quantity: 15 }, { name: "Shoes", quantity: 10 } ]; newItem: string = ''; newQuantity: number = 0; addItem() { const newItem: InventoryItem = { name: this.newItem, quantity: this.newQuantity }; this.inventory.push(newItem); this.newItem = ''; this.newQuantity = 0; } deleteItem(index: number) { this.inventory.splice(index, 1); } }
OUTPUT:
Lecture List – List of lectures scheduled for a course.
TYPESCRIPT:
import { Component } from '@angular/core'; interface Lecture { topic: string; date: Date; }import { Injectable } from '@angular/core'; @Injectable({ providedIn: 'root', }) @Component({ selector: 'app-lecture', templateUrl: './lecture.component.html', styleUrl: './lecture.component.css' }) export class LectureComponent { lectureList: Lecture[] = [ { topic: "Introduction to Programming", date: new Date('2024-01-15') }, { topic: "Data Structures", date: new Date('2024-01-22') } ]; newLecture: string = ''; addLecture() { const newLecture: Lecture = { topic: this.newLecture, date: new Date() }; this.lectureList.push(newLecture); this.newLecture = ''; } deleteLecture(index: number) { this.lectureList.splice(index, 1); } }
OUTPUT:
Stationery List – List of office stationery.
TYPESCRIPT:
import { Component } from '@angular/core'; import {FormsModule} from "@angular/forms"; interface StationeryItem { name: string; quantity: number; } import { Injectable } from '@angular/core'; @Injectable({ providedIn: 'root', }) @Component({ selector: 'app-stationery', templateUrl: './stationery.component.html', styleUrl: './stationery.component.css' }) export class StationeryComponent { stationeryList: StationeryItem[] = [ { name: "Pens", quantity: 50 }, { name: "Paper", quantity: 100 }, { name: "Staplers", quantity: 10 } ]; newItem: string = ''; newQuantity: number = 0; addItem() { const newItem: StationeryItem = { name: this.newItem, quantity: this.newQuantity }; this.stationeryList.push(newItem); this.newItem = ''; this.newQuantity = 0; } deleteItem(index: number) { this.stationeryList.splice(index, 1); } }
OUTPUT:
Flower List – List of flowers for a wedding.
TYPESCRIPT:
import { Component } from '@angular/core'; interface Flower { name: string; quantity: number; } import { Injectable } from '@angular/core'; @Injectable({ providedIn: 'root', }) @Component({ selector: 'app-flower', templateUrl: './flower.component.html', styleUrl: './flower.component.css' }) export class FlowerComponent { flowerList: Flower[] = [ { name: "Roses", quantity: 50 }, { name: "Lilies", quantity: 20 }, { name: "Hydrangeas", quantity: 15 } ]; newFlower: string = ''; newQuantity: number = 0; addFlower() { const newFlower: Flower = { name: this.newFlower, quantity: this.newQuantity }; this.flowerList.push(newFlower); this.newFlower = ''; this.newQuantity = 0; } deleteFlower(index: number) { this.flowerList.splice(index, 1); } }
OUTPUT:
Destination List – List of travel destinations.
TYPESCRIPT:
import { Component } from '@angular/core'; interface Destination { name: string; } import { Injectable } from '@angular/core'; @Injectable({ providedIn: 'root', }) @Component({ selector: 'app-destination', templateUrl: './destination.component.html', styleUrl: './destination.component.css' }) export class DestinationComponent { destinationList: Destination[] = [ { name: "Paris" }, { name: "Rome" }, { name: "Tokyo" } ]; newDestination: string = ''; addDestination() { const newDestination: Destination = { name: this.newDestination }; this.destinationList.push(newDestination); this.newDestination = ''; } deleteDestination(index: number) { this.destinationList.splice(index, 1); } }
OUTPUT:
Laptop List – List of laptop models.
TYPESCRIPT:
import { Component } from '@angular/core'; interface Laptop { model: string; }import { Injectable } from '@angular/core'; @Injectable({ providedIn: 'root', }) @Component({ selector: 'app-laptop', templateUrl: './laptop.component.html', styleUrl: './laptop.component.css' }) export class LaptopComponent { laptopList: Laptop[] = [ { model: "MacBook Pro 16" }, { model: "Dell XPS 13" }, { model: "Lenovo ThinkPad X1 Carbon" } ]; newLaptop: string = ''; addLaptop() { const newLaptop: Laptop = { model: this.newLaptop }; this.laptopList.push(newLaptop); this.newLaptop = ''; } deleteLaptop(index: number) { this.laptopList.splice(index, 1); } }
OUTPUT:
Laptop Specifications List – List of laptop specifications.
TYPESCRIPT:
import { Component } from '@angular/core'; import {FormsModule} from "@angular/forms"; interface LaptopSpec { model: string; processor: string; ram: number; storage: number; screenSize: number; } import { Injectable } from '@angular/core'; @Injectable({ providedIn: 'root', }) @Component({ selector: 'app-laptopspecifications', templateUrl: './laptopspecifications.component.html', styleUrl: './laptopspecifications.component.css' }) export class LaptopspecificationsComponent { laptopSpecsList: LaptopSpec[] = [ { model: "MacBook Pro 16", processor: "Apple M2 Pro", ram: 16, storage: 512, screenSize: 16.2 }, { model: "Dell XPS 13", processor: "Intel Core i7-1360P", ram: 16, storage: 512, screenSize: 13.4 }, { model: "Lenovo ThinkPad X1 Carbon", processor: "Intel Core i7-1360P", ram: 16, storage: 512, screenSize: 14 } ]; newModel: string = ''; newProcessor: string = ''; newRam: number = 0; newStorage: number = 0; newScreenSize: number = 0; addLaptop() { const newLaptop: LaptopSpec = { model: this.newModel, processor: this.newProcessor, ram: this.newRam, storage: this.newStorage, screenSize: this.newScreenSize }; this.laptopSpecsList.push(newLaptop); this.newModel = ''; this.newProcessor = ''; this.newRam = 0; this.newStorage = 0; this.newScreenSize = 0; } deleteLaptop(index: number) { this.laptopSpecsList.splice(index, 1); } }
OUTPUT:
Computer Hardware List – List of computer components.
TYPESCRIPT:
import { Component } from '@angular/core'; import {FormsModule} from "@angular/forms"; interface HardwareComponent { name: string; quantity: number; }import { Injectable } from '@angular/core'; @Injectable({ providedIn: 'root', }) @Component({ selector: 'app-computerhardware', templateUrl: './computerhardware.component.html', styleUrl: './computerhardware.component.css' }) export class ComputerhardwareComponent { hardwareList: HardwareComponent[] = [ { name: "CPU", quantity: 5 }, { name: "RAM", quantity: 10 }, { name: "Hard Drive", quantity: 8 } ]; newComponent: string = ''; newQuantity: number = 0; addComponent() { const newComponent: HardwareComponent = { name: this.newComponent, quantity: this.newQuantity }; this.hardwareList.push(newComponent); this.newComponent = ''; this.newQuantity = 0; } deleteComponent(index: number) { this.hardwareList.splice(index, 1); } }
OUTPUT:
Mobile App List – List of apps on a phone.
TYPESCRIPT:
import { Component } from '@angular/core'; interface App { name: string; }import { Injectable } from '@angular/core'; @Injectable({ providedIn: 'root', }) @Component({ selector: 'app-mobileapp', templateUrl: './mobileapp.component.html', styleUrl: './mobileapp.component.css' }) export class MobileappComponent { appList: App[] = [ { name: "Instagram" }, { name: "WhatsApp" }, { name: "YouTube" } ]; newApp: string = ''; addApp() { const newApp: App = { name: this.newApp }; this.appList.push(newApp); this.newApp = ''; } deleteApp(index: number) { this.appList.splice(index, 1); } }
OUTPUT:
Video List – List of videos in a library.
TYPESCRIPT:
import { Component } from '@angular/core'; interface Video { title: string; }import { Injectable } from '@angular/core'; @Injectable({ providedIn: 'root', }) @Component({ selector: 'app-video', templateUrl: './video.component.html', styleUrl: './video.component.css' }) export class VideoComponent { videoList: Video[] = [ { title: "The Shawshank Redemption" }, { title: "The Dark Knight" }, { title: "Pulp Fiction" } ]; newVideoTitle: string = ''; addVideo() { const newVideo: Video = { title: this.newVideoTitle }; this.videoList.push(newVideo); this.newVideoTitle = ''; } deleteVideo(index: number) { this.videoList.splice(index, 1); } }
OUTPUT:
TV Show List – List of TV shows available for streaming.
TYPESCRIPT:
import { Component } from '@angular/core'; interface TVShow { name: string; } import { Injectable } from '@angular/core'; @Injectable({ providedIn: 'root', }) @Component({ selector: 'app-tvshow', templateUrl: './tvshow.component.html', styleUrl: './tvshow.component.css' }) export class TvshowComponent { showList: TVShow[] = [ { name: "Stranger Things" }, { name: "Game of Thrones" } ]; newShow: string = ''; addShow() { const newShow: TVShow = { name: this.newShow }; this.showList.push(newShow); this.newShow = ''; } deleteShow(index: number) { this.showList.splice(index, 1); } }
OUTPUT:
Furniture List – List of furniture items in a store.
TYPESCRIPT:
import { Component } from '@angular/core'; interface Furniture { name: string; }import { Injectable } from '@angular/core'; @Injectable({ providedIn: 'root', }) @Component({ selector: 'app-furniture', templateUrl: './furniture.component.html', styleUrl: './furniture.component.css' }) export class FurnitureComponent { furnitureList: Furniture[] = [ { name: "Sofa" }, { name: "Table" }, { name: "Chair" } ]; newFurniture: string = ''; addFurniture() { const newFurniture: Furniture = { name: this.newFurniture }; this.furnitureList.push(newFurniture); this.newFurniture = ''; } deleteFurniture(index: number) { this.furnitureList.splice(index, 1); } }
OUTPUT:
Accessory List – List of accessories for mobile phones.
TYPESCRIPT:
import { Component } from '@angular/core'; import { Injectable } from '@angular/core'; interface Accessory { name: string; } @Injectable({ providedIn: 'root' }) export class AccessoryService { accessoryList: Accessory[] = [ { name: "Phone Case" }, { name: "Screen Protector" }, { name: "Headphones" } ]; newAccessory: string = ''; addAccessory() { const newAccessory: Accessory = { name: this.newAccessory }; this.accessoryList.push(newAccessory); this.newAccessory = ''; } deleteAccessory(index: number) { this.accessoryList.splice(index, 1); } } @Component({ selector: 'app-accessory', templateUrl: './accessory.component.html', styleUrl: './accessory.component.css' }) export class AccessoryComponent { accessoryList: Accessory[] = [ { name: "Phone Case" }, { name: "Screen Protector" }, { name: "Headphones" } ]; newAccessory: string = ''; addAccessory() { const newAccessory: Accessory = { name: this.newAccessory }; this.accessoryList.push(newAccessory); this.newAccessory = ''; } deleteAccessory(index: number) { this.accessoryList.splice(index, 1); } }
OUTPUT:
Building List – List of buildings in a campus.
TYPESCRIPT:
import { Component } from '@angular/core'; interface Building { name: string; } import { Injectable } from '@angular/core'; @Injectable({ providedIn: 'root', }) @Component({ selector: 'app-building', templateUrl: './building.component.html', styleUrl: './building.component.css' }) export class BuildingComponent { buildingList: Building[] = [ { name: "Main Building" }, { name: "Library" }, { name: "Science Hall" } ]; newBuilding: string = ''; addBuilding() { const newBuilding: Building = { name: this.newBuilding }; this.buildingList.push(newBuilding); this.newBuilding = ''; } deleteBuilding(index: number) { this.buildingList.splice(index, 1); } }
OUTPUT:
Painting List – List of famous paintings.
TYPESCRIPT:
import { Component } from '@angular/core'; interface Painting { title: string; } import { Injectable } from '@angular/core'; @Injectable({ providedIn: 'root', }) @Component({ selector: 'app-painting', templateUrl: './painting.component.html', styleUrl: './painting.component.css' }) export class PaintingComponent { paintingList: Painting[] = [ { title: "Mona Lisa" }, { title: "The Starry Night" }, { title: "Girl with a Pearl Earring" } ]; newPainting: string = ''; addPainting() { const newPainting: Painting = { title: this.newPainting }; this.paintingList.push(newPainting); this.newPainting = ''; } deletePainting(index: number) { this.paintingList.splice(index, 1); } }
OUTPUT:
Artist List – List of famous artists.
TYPESCRIPT:
import { Component } from '@angular/core'; interface Artist { name: string; } import { Injectable } from '@angular/core'; @Injectable({ providedIn: 'root', }) @Component({ selector: 'app-artist', templateUrl: './artist.component.html', styleUrl: './artist.component.css' }) export class ArtistComponent { artistList: Artist[] = [ { name: "Leonardo da Vinci" }, { name: "Vincent van Gogh" } ]; newArtist: string = ''; addArtist() { const newArtist: Artist = { name: this.newArtist }; this.artistList.push(newArtist); this.newArtist = ''; } deleteArtist(index: number) { this.artistList.splice(index, 1); } }
OUTPUT:
Composer List – List of famous music composers.
TYPESCRIPT:
import { Component } from '@angular/core'; interface Composer { name: string; }import { Injectable } from '@angular/core'; @Injectable({ providedIn: 'root', }) @Component({ selector: 'app-composer', templateUrl: './composer.component.html', styleUrl: './composer.component.css' }) export class ComposerComponent { composerList: Composer[] = [ { name: "Ludwig van Beethoven" }, { name: "Wolfgang Amadeus Mozart" }, { name: "Johann Sebastian Bach" } ]; newComposer: string = ''; addComposer() { const newComposer: Composer = { name: this.newComposer }; this.composerList.push(newComposer); this.newComposer = ''; } deleteComposer(index: number) { this.composerList.splice(index, 1); } }
OUTPUT:
Podcast List – List of podcast episodes.
TYPESCRIPT:
import { Component } from '@angular/core'; interface PodcastEpisode { title: string; } import { Injectable } from '@angular/core'; @Injectable({ providedIn: 'root', }) @Component({ selector: 'app-podcast', templateUrl: './podcast.component.html', styleUrl: './podcast.component.css' }) export class PodcastComponent { episodeList: PodcastEpisode[] = [ { title: "Episode 1: The Introduction" }, { title: "Episode 2: The Big Reveal" }, { title: "Episode 3: The Twist" } ]; newEpisodeTitle: string = ''; addEpisode() { const newEpisode: PodcastEpisode = { title: this.newEpisodeTitle }; this.episodeList.push(newEpisode); this.newEpisodeTitle = ''; } deleteEpisode(index: number) { this.episodeList.splice(index, 1); } }
OUTPUT:
Exercise List – List of exercises for a workout routine.
TYPESCRIPT:
import { Component } from '@angular/core'; interface Exercise { name: string; sets: number; reps: number; } import { Injectable } from '@angular/core'; @Injectable({ providedIn: 'root', }) @Component({ selector: 'app-exercise', templateUrl: './exercise.component.html', styleUrl: './exercise.component.css' }) export class ExerciseComponent { exerciseList: Exercise[] = [ { name: "Push-ups", sets: 3, reps: 10 }, { name: "Squats", sets: 3, reps: 12 }, { name: "Pull-ups", sets: 3, reps: 8 } ]; newExercise: string = ''; newSets: number = 0; newReps: number = 0; addExercise() { const newExercise: Exercise = { name: this.newExercise, sets: this.newSets, reps: this.newReps }; this.exerciseList.push(newExercise); this.newExercise = ''; this.newSets = 0; this.newReps = 0; } deleteExercise(index: number) { this.exerciseList.splice(index, 1); } }
OUTPUT:
Meal Plan List – List of meals in a weekly plan.
TYPESCRIPT:
import { Component } from '@angular/core'; interface Meal { name: string; day: string; }import { Injectable } from '@angular/core'; @Injectable({ providedIn: 'root', }) @Component({ selector: 'app-mealplan', templateUrl: './mealplan.component.html', styleUrl: './mealplan.component.css' }) export class MealplanComponent { mealPlan: Meal[] = [ { name: "Breakfast Burrito", day: "Monday" }, { name: "Chicken Salad", day: "Tuesday" }, { name: "Pasta with Veggies", day: "Wednesday" } ]; newMeal: string = ''; newDay: string = ''; days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]; addMeal() { const newMeal: Meal = { name: this.newMeal, day: this.newDay }; this.mealPlan.push(newMeal); this.newMeal = ''; this.newDay = ''; } deleteMeal(index: number) { this.mealPlan.splice(index, 1); } }
OUTPUT:
Budget List – List of budget items for a project.
TYPESCRIPT:
import { Component } from '@angular/core'; interface BudgetItem { name: string; cost: number; } import { Injectable } from '@angular/core'; @Injectable({ providedIn: 'root', }) @Component({ selector: 'app-budget', templateUrl: './budget.component.html', styleUrl: './budget.component.css' }) export class BudgetComponent { budgetItems: BudgetItem[] = [ { name: "Software", cost: 500 }, { name: "Hardware", cost: 1000 }, { name: "Marketing", cost: 200 } ]; newItem: string = ''; newCost: number = 0; addItem() { const newItem: BudgetItem = { name: this.newItem, cost: this.newCost }; this.budgetItems.push(newItem); this.newItem = ''; this.newCost = 0; } deleteItem(index: number) { this.budgetItems.splice(index, 1); } getTotalCost(): number { return this.budgetItems.reduce((total, item) => total + item.cost, 0); } }
OUTPUT:
Presentation List – List of presentation topics.
TYPESCRIPT:
import { Component } from '@angular/core'; interface PresentationTopic { name: string; }import { Injectable } from '@angular/core'; @Injectable({ providedIn: 'root', }) @Component({ selector: 'app-presentation', templateUrl: './presentation.component.html', styleUrl: './presentation.component.css' }) export class PresentationComponent { topicList: PresentationTopic[] = [ { name: "The Future of Artificial Intelligence" }, { name: "Sustainable Living Practices" }, { name: "The History of Music" } ]; newTopic: string = ''; addTopic() { const newTopic: PresentationTopic = { name: this.newTopic }; this.topicList.push(newTopic); this.newTopic = ''; } deleteTopic(index: number) { this.topicList.splice(index, 1); } }
OUTPUT:
Tour List – List of tour dates for a band.
TYPESCRIPT:
import { Component } from '@angular/core'; interface TourDate { city: string; date: Date; } import { Injectable } from '@angular/core'; @Injectable({ providedIn: 'root', }) @Component({ selector: 'app-tour', templateUrl: './tour.component.html', styleUrl: './tour.component.css' }) export class TourComponent { tourDates: TourDate[] = [ { city: "New York", date: new Date('2024-03-15') }, { city: "Los Angeles", date: new Date('2024-03-22') }, { city: "Chicago", date: new Date('2024-03-29') } ]; newCity: string = ''; newDate: Date = new Date(); addTourDate() { const newTourDate: TourDate = { city: this.newCity, date: this.newDate }; this.tourDates.push(newTourDate); this.newCity = ''; this.newDate = new Date(); } deleteTourDate(index: number) { this.tourDates.splice(index, 1); } }
OUTPUT:
Event List – List of upcoming events.
TYPESCRIPT:
import { Component } from '@angular/core'; interface Event { name: string; date: Date; } import { Injectable } from '@angular/core'; @Injectable({ providedIn: 'root', }) @Component({ selector: 'app-event', templateUrl: './event.component.html', styleUrl: './event.component.css' }) export class EventComponent { eventList: Event[] = [ { name: "Summer Festival", date: new Date('2024-06-15') }, { name: "Tech Conference", date: new Date('2024-09-20') }, { name: "Art Exhibition", date: new Date('2024-11-05') } ]; newEvent: string = ''; newDate: Date = new Date(); addEvent() { const newEvent: Event = { name: this.newEvent, date: this.newDate }; this.eventList.push(newEvent); this.newEvent = ''; this.newDate = new Date(); } deleteEvent(index: number) { this.eventList.splice(index, 1); } }
OUTPUT:
Developer Tools List – List of software developer tools.
TYPESCRIPT:
import { Component } from '@angular/core'; interface DevTool { name: string; category: string; } import { Injectable } from '@angular/core'; @Injectable({ providedIn: 'root', }) @Component({ selector: 'app-developer', templateUrl: './developer.component.html', styleUrl: './developer.component.css' }) export class DeveloperComponent { devToolsList: DevTool[] = [ { name: "Visual Studio Code", category: "Code Editor" }, { name: "Git", category: "Version Control" }, { name: "Postman", category: "API Testing" } ]; newTool: string = ''; newCategory: string = ''; addTool() { const newTool: DevTool = { name: this.newTool, category: this.newCategory }; this.devToolsList.push(newTool); this.newTool = ''; this.newCategory = ''; } deleteTool(index: number) { this.devToolsList.splice(index, 1); } }
OUTPUT:
Framework List – List of web development frameworks.
TYPESCRIPT:
import { Component } from '@angular/core'; interface Framework { name: string; type: string; }import { Injectable } from '@angular/core'; @Injectable({ providedIn: 'root', }) @Component({ selector: 'app-framework', templateUrl: './framework.component.html', styleUrl: './framework.component.css' }) export class FrameworkComponent { frameworkList: Framework[] = [ { name: "Angular", type: "Front-End" }, { name: "React", type: "Front-End" }, { name: "Vue.js", type: "Front-End" }, { name: "Express.js", type: "Back-End" }, { name: "Django", type: "Back-End" } ]; newFramework: string = ''; newType: string = ''; frameworkTypes = ["Front-End", "Back-End", "Full-Stack"]; addFramework() { const newFramework: Framework = { name: this.newFramework, type: this.newType }; this.frameworkList.push(newFramework); this.newFramework = ''; this.newType = ''; } deleteFramework(index: number) { this.frameworkList.splice(index, 1); } }
OUTPUT:
Library List – List of libraries used in a project.
TYPESCRIPT:
import { Component } from '@angular/core'; interface Library { name: string; }import { Injectable } from '@angular/core'; @Injectable({ providedIn: 'root', }) @Component({ selector: 'app-library', templateUrl: './library.component.html', styleUrl: './library.component.css' }) export class LibraryComponent { libraryList: Library[] = [ { name: "lodash" }, { name: "moment.js" }, { name: "axios" } ]; newLibrary: string = ''; addLibrary() { const newLibrary: Library = { name: this.newLibrary }; this.libraryList.push(newLibrary); this.newLibrary = ''; } deleteLibrary(index: number) { this.libraryList.splice(index, 1); } }
OUTPUT:
GITHUB LINK:
https://github.com/jerome09232/activity15
FIREBASE HOSTING: