Research Angular Services


Angular Services and Dependency Injection
Service is a broad category encompassing any value, function, or feature that an application needs. A service is typically a class with a narrow, well-defined purpose. It should do something specific and do it well.
Angular distinguishes components from services to increase modularity and reusability.
Angular services are a core feature that provide a way to encapsulate reusable business logic, making it accessible across multiple components in an application. They are designed to separate concerns by handling tasks like data fetching, logging, or authentication, which keeps components focused on the user interface. Services are typically singleton objects, meaning they are created once and shared throughout the application. Using Angular's dependency injection system, services can be easily injected into components or other services, promoting modular, testable, and maintainable code. This approach helps streamline complex functionality and ensures code reusability.
If you haven't read the following, just click on the links I provided…
Angular with TypeScript and Data Structures
https://walterific.hashnode.dev/angular-with-typescript-and-data-structures
Firebase Deployment
https://walterific.hashnode.dev/documentation-of-firebase
50 Angular Services
- Student List
// studentlist.service.ts
import { Injectable } from '@angular/core';
export interface StudentList {
id: string;
name: string;
age: number;
}
@Injectable({
providedIn: 'root',
})
export class StudentListService {
private students: StudentList[] = [];
addStudent(id: string, name: string, age: number): void {
this.students.push({
id,
name,
age
});
}
getStudents(): StudentList[] {
return this.students;
}
}
// studentlist.component.ts
import { Component } from '@angular/core';
import { StudentListService, StudentList } from '../services/studentlist/studentlist.service';
@Component({
selector: 'app-studentlist',
templateUrl: './studentlist.component.html',
styleUrls: ['./studentlist.component.css'],
})
export class StudentListComponent {
students: StudentList[] = [];
id: string = '';
name: string = '';
age: number = 0;
constructor(private studentListService: StudentListService) {
this.students = this.studentListService.getStudents();
}
addStudent(): void {
this.studentListService.addStudent(this.id, this.name, this.age);
this.clearForm();
}
clearForm(): void {
this.id = '';
this.name = '';
this.age = 0;
}
}
OUTPUT:
- Employee List
// employeelist.service.ts
import { Injectable } from '@angular/core';
export interface employeeList {
id: string;
name: string;
job: string;
}
@Injectable ({
providedIn: 'root',
})
export class EmployeeListService {
private employee: employeeList[] = [];
addEmployee(id: string, name: string, job: string): void {
this.employee.push({
id,
name,
job
});
}
getEmployee(): employeeList[] {
return this.employee;
}
}
// employeelist.component.ts
import { Component } from '@angular/core';
import { EmployeeListService, employeeList } from '../services/employeelist/employeelist.service';
@Component({
selector: 'app-employeelist',
templateUrl: './employeelist.component.html',
styleUrl: './employeelist.component.css'
})
export class EmployeelistComponent {
employee: employeeList[] = [];
id: string = '';
name: string = '';
job: string = '';
constructor(private employeeListService: EmployeeListService) {
this.employee = this.employeeListService.getEmployee();
}
addEmployee(): void {
this.employeeListService.addEmployee(this.id, this.name, this.job);
this.clearForm();
}
clearForm(): void {
this.id = '';
this.name = '';
this.job = '';
}
}
OUTPUT:
- Fruit List
// fruitlist.service.ts
import { Injectable } from '@angular/core';
export interface FruitList {
id: string;
name: string;
number: number;
}
@Injectable({
providedIn: 'root',
})
export class FruitListService {
private fruits: FruitList[] = [];
addFruit(id: string, name: string, number: number): void {
this.fruits.push({
id,
name,
number
});
}
getFruits(): FruitList[] {
return this.fruits;
}
}
// fruitlist.component.ts
import { Component } from '@angular/core';
import { FruitListService, FruitList } from '../services/fruitlist/fruitlist.service';
@Component({
selector: 'app-fruitlist',
templateUrl: './fruitlist.component.html',
styleUrl: './fruitlist.component.css'
})
export class FruitlistComponent {
fruits: FruitList[] = [];
id: string = '';
name: string = '';
number: number = 0;
constructor(private fruitListService: FruitListService) {
this.fruits = this.fruitListService.getFruits();
}
addFruit(): void {
this.fruitListService.addFruit(this.id, this.name, this.number);
this.clearForm();
}
clearForm(): void {
this.id = '';
this.name = '';
this.number = 0;
}
}
OUTPUT:
- Book List
// booklist.service.ts
import { Injectable } from '@angular/core';
export interface BookList {
id: string;
bookname: string;
yearPublished: number;
}
@Injectable({
providedIn: 'root',
})
export class BookListService {
private books: BookList[] = [];
addBook(id: string, bookname: string, yearPublished: number): void {
this.books.push({
id,
bookname,
yearPublished
});
}
getBooks(): BookList[] {
return this.books;
}
}
// booklist.component.ts
import { Component } from '@angular/core';
import { BookListService, BookList } from '../services/booklist/booklist.service';
@Component({
selector: 'app-booklist',
templateUrl: './booklist.component.html',
styleUrl: './booklist.component.css'
})
export class BooklistComponent {
books: BookList[] = [];
id: string = '';
bookname: string = '';
yearPublished: number = 0;
constructor(private bookListService: BookListService) {
this.books = this.bookListService.getBooks();
}
addBook(): void {
this.bookListService.addBook(this.id, this.bookname, this.yearPublished);
this.clearFrom();
}
clearFrom(): void {
this.id = '';
this.bookname = '';
this.yearPublished = 0;
}
}
OUTPUT:
- Course List
// courselist.service.ts
import { Injectable } from '@angular/core';
export interface CourseList {
id: string;
courseName: string;
}
@Injectable({
providedIn: 'root',
})
export class CourseListService {
private courses: CourseList[] = [];
addCourse(id: string, courseName: string): void {
this.courses.push({
id,
courseName
});
}
getCourses(): CourseList[] {
return this.courses;
}
}
// courselist.component.ts
import { Component } from '@angular/core';
import { CourseListService, CourseList } from '../services/courselist/courselist.service';
@Component({
selector: 'app-courselist',
templateUrl: './courselist.component.html',
styleUrl: './courselist.component.css'
})
export class CourseListComponent {
courses: CourseList[] = [];
id: string = '';
courseName: string = '';
constructor(private courseListService: CourseListService) {
this.courses = this.courseListService.getCourses();
}
addCourse(): void {
this.courseListService.addCourse(this.id, this.courseName);
this.clearForm();
}
clearForm(): void {
this.id = '';
this.courseName = '';
}
}
OUTPUT:
- City List
// citylist.service.ts
import { Injectable } from "@angular/core";
export interface CityList {
id: string;
city: string;
}
@Injectable({
providedIn: 'root',
})
export class CityListService {
private cities: CityList[] = [];
addCity(id: string, city: string): void {
this.cities.push({
id,
city
});
}
getCities(): CityList[] {
return this.cities;
}
}
// citylist.component.ts
import { Component } from '@angular/core';
import { CityListService, CityList } from '../services/citylist/citylist.service';
@Component({
selector: 'app-citylist',
templateUrl: './citylist.component.html',
styleUrl: './citylist.component.css'
})
export class CitylistComponent {
cities: CityList[] = [];
id: string = '';
city: string = '';
constructor(private cityListService: CityListService) {
this.cities = this.cityListService.getCities();
}
addCity(): void {
this.cityListService.addCity(this.id, this.city );
this.clearForm();
}
clearForm(): void {
this.id = '';
this.city = '';
}
}
OUTPUT:
- Movie List
// movielist.service.ts
import { Injectable } from '@angular/core';
export interface MovieList {
id: string;
movie: string;
yearReleased: number;
}
@Injectable({
providedIn: 'root',
})
export class MovieListService {
private movies: MovieList[] = [];
addMovie(id: string, movie: string, yearReleased: number): void {
this.movies.push({
id,
movie,
yearReleased
});
}
getMovies(): MovieList[] {
return this.movies;
}
}
// movielist.component.ts
import { Component } from '@angular/core';
import { MovieListService, MovieList } from '../services/movielist/movielist.service';
@Component({
selector: 'app-movielist',
templateUrl: './movielist.component.html',
styleUrl: './movielist.component.css'
})
export class MovielistComponent {
movies: MovieList[] = [];
id: string = '';
movie: string = '';
yearReleased: number = 0;
constructor(private movieListService: MovieListService) {
this.movies = this.movieListService.getMovies();
}
addMovie(): void {
this.movieListService.addMovie(this.id, this.movie, this.yearReleased);
this.clearForm();
}
clearForm(): void {
this.id = '';
this.movie = '';
this.yearReleased = 0;
}
}
OUTPUT:
- Car Model List
// carmodellist.service.ts
import { Injectable } from '@angular/core';
export interface CarmodelList {
id: string;
carName: string;
yearReleased: number;
}
@Injectable({
providedIn: 'root',
})
export class CarmodelListService {
private cars: CarmodelList[] = [];
addCar(id: string, carName: string, yearReleased: number): void {
this.cars.push({
id,
carName,
yearReleased
});
}
getCars(): CarmodelList[] {
return this.cars;
}
}
// carmodellist.component.ts
import { Component } from '@angular/core';
import { CarmodelListService, CarmodelList } from '../services/carmodellist/carmodellist.service';
@Component({
selector: 'app-carmodellist',
templateUrl: './carmodellist.component.html',
styleUrl: './carmodellist.component.css'
})
export class CarmodellistComponent {
cars: CarmodelList[] = [];
id: string = '';
carName: string = '';
yearReleased: number = 0;
constructor(private carmodelListService: CarmodelListService) {
this.cars = this.carmodelListService.getCars();
}
addCar(): void {
this.carmodelListService.addCar(this.id, this.carName, this.yearReleased);
this.clearForm();
}
clearForm(): void {
this.id = '';
this.carName = '';
this.yearReleased = 0;
}
}
OUTPUT:
- Product List
// productlist.service.ts
import { Injectable } from '@angular/core';
export interface ProductList {
id: string;
productName: string;
manufacture: number;
expiration: number;
}
@Injectable({
providedIn: 'root',
})
export class ProductListService {
private products: ProductList[] = [];
addProduct(id: string, productName: string, manufacture: number, expiration: number): void {
this.products.push({
id,
productName,
manufacture,
expiration
});
}
getProducts(): ProductList[] {
return this.products;
}
}
// productlist.component.ts
import { Component } from '@angular/core';
import { ProductListService, ProductList } from '../services/productlist/productlist.service';
@Component({
selector: 'app-productlist',
templateUrl: './productlist.component.html',
styleUrl: './productlist.component.css'
})
export class ProductlistComponent {
products: ProductList[] = [];
id: string = '';
productName: string = '';
manufacture: number = 0;
expiration: number = 0;
constructor(private productListService: ProductListService) {
this.products = this.productListService.getProducts();
}
addProduct(): void {
this.productListService.addProduct(this.id, this.productName, this.manufacture, this.expiration);
this.clearForm();
}
clearForm(): void {
this.id = '';
this.productName = '';
this.manufacture = 0;
this.expiration = 0;
}
}
OUTPUT:
- Subject List
// subjectlist.service.ts
import { Injectable } from '@angular/core';
export interface SubjectList {
id: string;
subject: string;
schedule: string;
}
@Injectable({
providedIn: 'root',
})
export class SubjectListService {
private subjects: SubjectList[] = [];
addSubject(id: string, subject: string, schedule: string): void {
this.subjects.push({
id,
subject,
schedule
});
}
getSubjects(): SubjectList[] {
return this.subjects;
}
}
// subjectlist.component.ts
import { Component } from '@angular/core';
import { SubjectListService, SubjectList } from '../services/subjectlist/subjectlist.service';
@Component({
selector: 'app-subjectlist',
templateUrl: './subjectlist.component.html',
styleUrl: './subjectlist.component.css'
})
export class SubjectlistComponent {
subjects: SubjectList[] = [];
id: string = '';
subject: string = '';
schedule: string = '';
constructor(private subjectListService: SubjectListService) {
this.subjects = this.subjectListService.getSubjects();
}
addSubject(): void {
this.subjectListService.addSubject(this.id, this.subject, this.schedule);
this.clearForm();
}
clearForm(): void {
this.id = '';
this.subject = '';
this.schedule = '';
}
}
OUTPUT:
- Country List
// countrylist.service.ts
import { Injectable } from '@angular/core';
export interface CountryList {
id: string;
name: string;
}
@Injectable({
providedIn: 'root',
})
export class CountryListService {
private countries: CountryList[] = [];
addCountry(id: string, name: string): void {
this.countries.push({ id, name });
}
getCountries(): CountryList[] {
return this.countries;
}
}
// countrylist.component.ts
import { Component } from '@angular/core';
import { CountryListService, CountryList } from '../services/countrylist/countrylist.service';
@Component({
selector: 'app-countrylist',
templateUrl: './countrylist.component.html',
styleUrls: ['./countrylist.component.css'],
})
export class CountryListComponent {
countries: CountryList[] = [];
id: string = '';
name: string = '';
constructor(private countryListService: CountryListService) {
this.countries = this.countryListService.getCountries();
}
addCountry(): void {
this.countryListService.addCountry(this.id, this.name);
this.clearForm();
}
clearForm(): void {
this.id = '';
this.name = '';
}
}
OUTPUT:
- Sport List
// sportlist.service.ts
import { Injectable } from '@angular/core';
export interface SportList {
id: string;
sport: string;
}
@Injectable({
providedIn: 'root',
})
export class SportListService {
private sports: SportList[] = [];
addSport(id: string, sport: string): void {
this.sports.push({ id, sport });
}
getSports(): SportList[] {
return this.sports;
}
}
// sportlist.component.ts
import { Component } from '@angular/core';
import { SportListService, SportList } from '../services/sportlist/sportlist.service';
@Component({
selector: 'app-sportslist',
templateUrl: './sportslist.component.html',
styleUrl: './sportslist.component.css'
})
export class SportslistComponent {
sports: SportList[] = [];
id: string = '';
sport: string = '';
constructor(private sportListService: SportListService) {
this.sports = this.sportListService.getSports();
}
addSport(): void {
this.sportListService.addSport(this.id, this.sport);
this.clearForm();
}
clearForm(): void {
this.id = '';
this.sport = '';
}
}
OUTPUT:
- Vegetable List
// vegetablelist.service.ts
import { Injectable } from '@angular/core';
export interface VegetableList {
id: string;
vegetable: string;
quantity: number;
}
@Injectable({
providedIn: 'root',
})
export class VegetableListService {
private vegetables: VegetableList[] = [];
addVegetable(id: string, vegetable: string, quantity: number): void {
this.vegetables.push({ id, vegetable, quantity });
}
getVegetables(): VegetableList[] {
return this.vegetables;
}
}
// vegetablelist.component.ts
import { Component } from '@angular/core';
import { VegetableListService, VegetableList } from '../services/vegetablelist/vegetablelist.service';
@Component({
selector: 'app-vegetablelist',
templateUrl: './vegetablelist.component.html',
styleUrl: './vegetablelist.component.css'
})
export class VegetablelistComponent {
vegetables: VegetableList[] = [];
id: string = '';
vegetable: string = '';
quantity: number = 0;
constructor(private vegetableListService: VegetableListService) {
this.vegetables = this.vegetableListService.getVegetables();
}
addVegetable(): void {
this.vegetableListService.addVegetable(this.id, this.vegetable, this.quantity);
this.clearForm();
}
clearForm(): void {
this.id = '';
this.vegetable = '';
this.quantity = 0;
}
}
OUTPUT:
- Animal List
// animallist.service.ts
import { Injectable } from '@angular/core';
export interface AnimalList {
id: string;
animal: string;
breed: string;
}
@Injectable({
providedIn: 'root',
})
export class AnimalListService {
private animals: AnimalList[] = [];
addAnimal(id: string, animal: string, breed: string): void {
this.animals.push({ id, animal, breed });
}
getAnimals(): AnimalList[] {
return this.animals;
}
}
// animallist.component.ts
import { Component } from '@angular/core';
import { AnimalListService, AnimalList } from '../services/animallist/animallist.service';
@Component({
selector: 'app-animallist',
templateUrl: './animallist.component.html',
styleUrl: './animallist.component.css'
})
export class AnimallistComponent {
animals: AnimalList[] = [];
id: string = '';
animal: string = '';
breed: string = '';
constructor(private animalListService: AnimalListService) {
this.animals = this.animalListService.getAnimals();
}
addAnimal(): void {
this.animalListService.addAnimal(this.id, this.animal, this.breed);
this.clearForm();
}
clearForm(): void {
this.id = '';
this.animal = '';
this.breed = '';
}
}
OUTPUT:
- Tool List
// toollist.service.ts
import { Injectable } from '@angular/core';
export interface ToolList {
id: string;
tool: string;
}
@Injectable({
providedIn: 'root',
})
export class ToolListService {
private tools: ToolList[] = [];
addTool(id: string, tool: string): void {
this.tools.push({ id, tool });
}
getTools(): ToolList[] {
return this.tools;
}
}
// toollist.component.ts
import { Component } from '@angular/core';
import { ToolListService, ToolList } from '../services/toollist/toollist.service';
@Component({
selector: 'app-toollist',
templateUrl: './toollist.component.html',
styleUrl: './toollist.component.css'
})
export class ToollistComponent {
tools: ToolList[] = [];
id: string = '';
tool: string = '';
constructor(private toolListService: ToolListService) {
this.tools = this.toolListService.getTools();
}
addTool(): void {
this.toolListService.addTool(this.id, this.tool);
this.clearForm();
}
clearForm(): void {
this.id = '';
this.tool = '';
}
}
OUTPUT:
- Language List
// languagelist.service.ts
import { Injectable } from '@angular/core';
export interface LanguageList {
id: string;
language: string;
}
@Injectable({
providedIn: 'root',
})
export class LanguageListService {
private languages: LanguageList[] = [];
addLanguage(id: string, language: string): void {
this.languages.push({ id, language });
}
getLanguages(): LanguageList[] {
return this.languages;
}
}
// languagelist.component.ts
import { Component } from '@angular/core';
import { LanguageListService, LanguageList } from '../services/languagelist/languagelist.service';
@Component({
selector: 'app-languagelist',
templateUrl: './languagelist.component.html',
styleUrl: './languagelist.component.css'
})
export class LanguagelistComponent {
languages: LanguageList[] = [];
id: string = '';
language: string = '';
constructor(private languageListService: LanguageListService) {
this.languages = this.languageListService.getLanguages();
}
addLanguage(): void {
this.languageListService.addLanguage(this.id, this.language);
this.clearForm();
}
clearForm(): void {
this.id = '';
this.language = '';
}
}
OUTPUT:
- Game List
// gamelist.service.ts
import { Injectable } from '@angular/core';
export interface GameList {
id: string;
game: string;
genre: string;
}
@Injectable({
providedIn: 'root',
})
export class GameListService {
private games: GameList[] = [];
addGame(id: string, game: string, genre: string): void {
this.games.push({ id, game, genre });
}
getGames(): GameList[] {
return this.games;
}
}
// gamelist.component.ts
import { Component } from '@angular/core';
import { GameListService, GameList } from '../services/gamelist/gamelist.service';
@Component({
selector: 'app-gamelist',
templateUrl: './gamelist.component.html',
styleUrl: './gamelist.component.css'
})
export class GamelistComponent {
games: GameList[] = [];
id: string = '';
game: string = '';
genre: string = '';
constructor(private gameListService: GameListService) {
this.games = this.gameListService.getGames();
}
addGame(): void {
this.gameListService.addGame(this.id, this.game, this.genre);
this.clearForm();
}
clearForm(): void {
this.id = '';
this.game = '';
this.genre = '';
}
}
OUTPUT:
- Software List
// softwarelist.service.ts
import { Injectable } from '@angular/core';
export interface SoftwareList {
id: string;
software: string;
version: string;
}
@Injectable({
providedIn: 'root',
})
export class SoftwareListService {
private softwareList: SoftwareList[] = [];
addSoftware(id: string, software: string, version: string): void {
this.softwareList.push({ id, software, version });
}
getSoftwareList(): SoftwareList[] {
return this.softwareList;
}
}
// softwarelist.component.ts
import { Component } from '@angular/core';
import { SoftwareListService, SoftwareList } from '../services/softwarelist/softwarelist.service';
@Component({
selector: 'app-softwarelist',
templateUrl: './softwarelist.component.html',
styleUrl: './softwarelist.component.css'
})
export class SoftwarelistComponent {
softwareList: SoftwareList[] = [];
id: string = '';
software: string = '';
version: string = '';
constructor(private softwareListService: SoftwareListService) {
this.softwareList = this.softwareListService.getSoftwareList();
}
addSoftware(): void {
this.softwareListService.addSoftware(this.id, this.software, this.version);
this.clearForm();
}
clearForm(): void {
this.id = '';
this.software = '';
this.version = '';
}
}
OUTPUT:
- Phone Contact List
// phonecontactlist.service.ts
import { Injectable } from '@angular/core';
export interface PhoneContact {
id: string;
contactName: string;
number: string;
}
@Injectable({
providedIn: 'root',
})
export class PhoneContactListService {
private contacts: PhoneContact[] = [];
addContact(id: string, contactName: string, number: string): void {
this.contacts.push({ id, contactName, number });
}
getContacts(): PhoneContact[] {
return this.contacts;
}
}
// phonecontactlist.component.ts
import { Component } from '@angular/core';
import { PhoneContactListService, PhoneContact } from '../services/phonecontactlist/phonecontactlist.service';
@Component({
selector: 'app-phonecontactlist',
templateUrl: './phonecontactlist.component.html',
styleUrl: './phonecontactlist.component.css'
})
export class PhonecontactlistComponent {
contacts: PhoneContact[] = [];
id: string = '';
contactName: string = '';
number: string = '';
constructor(private phoneContactListService: PhoneContactListService) {
this.contacts = this.phoneContactListService.getContacts();
}
addContact(): void {
this.phoneContactListService.addContact(this.id, this.contactName, this.number);
this.clearForm();
}
clearForm(): void {
this.id = '';
this.contactName = '';
this.number = '';
}
}
OUTPUT:
- Music Playlist
// musicplaylist.service.ts
import { Injectable } from '@angular/core';
export interface Music {
id: string;
music: string;
genre: string;
}
@Injectable({
providedIn: 'root',
})
export class MusicPlaylistService {
private playlist: Music[] = [];
addMusic(id: string, music: string, genre: string): void {
this.playlist.push({ id, music, genre });
}
getPlaylist(): Music[] {
return this.playlist;
}
}
// musicplaylist.component.ts
import { Component } from '@angular/core';
import { MusicPlaylistService, Music } from '../services/musicplaylist/musicplaylist.service';
@Component({
selector: 'app-musicplaylist',
templateUrl: './musicplaylist.component.html',
styleUrl: './musicplaylist.component.css'
})
export class MusicplaylistComponent {
playlist: Music[] = [];
id: string = '';
music: string = '';
genre: string = '';
constructor(private musicPlaylistService: MusicPlaylistService) {
this.playlist = this.musicPlaylistService.getPlaylist();
}
addMusic(): void {
this.musicPlaylistService.addMusic(this.id, this.music, this.genre);
this.clearForm();
}
clearForm(): void {
this.id = '';
this.music = '';
this.genre = '';
}
}
OUTPUT:
- Food Menu
// foodmenu.service.ts
import { Injectable } from '@angular/core';
export interface FoodItem {
id: string;
food: string;
price: number;
}
@Injectable({
providedIn: 'root',
})
export class FoodMenuService {
private menu: FoodItem[] = [];
addFood(id: string, food: string, price: number): void {
this.menu.push({ id, food, price });
}
getMenu(): FoodItem[] {
return this.menu;
}
}
// foodmenu.component.ts
import { Component } from '@angular/core';
import { FoodMenuService, FoodItem } from '../services/foodmenu/foodmenu.service';
@Component({
selector: 'app-foodmenu',
templateUrl: './foodmenu.component.html',
styleUrl: './foodmenu.component.css'
})
export class FoodmenuComponent {
menu: FoodItem[] = [];
id: string = '';
food: string = '';
price: number = 0;
constructor(private foodMenuService: FoodMenuService) {
this.menu = this.foodMenuService.getMenu();
}
addFood(): void {
this.foodMenuService.addFood(this.id, this.food, this.price);
this.clearForm();
}
clearForm(): void {
this.id = '';
this.food = '';
this.price = 0;
}
}
OUTPUT:
- Grocery List
// grocerylist.service.ts
import { Injectable } from '@angular/core';
export interface GroceryItem {
id: string;
product: string;
quantity: number;
price: number;
total: number;
}
@Injectable({
providedIn: 'root',
})
export class GroceryListService {
private groceryList: GroceryItem[] = [];
addGrocery(id: string, product: string, quantity: number, price: number): void {
const total = quantity * price;
this.groceryList.push({ id, product, quantity, price, total });
}
getGroceryList(): GroceryItem[] {
return this.groceryList;
}
}
// grocerylist.component.ts
import { Component } from '@angular/core';
import { GroceryListService, GroceryItem } from '../services/grocerylist/grocerylist.service';
@Component({
selector: 'app-grocerylist',
templateUrl: './grocerylist.component.html',
styleUrl: './grocerylist.component.css'
})
export class GrocerylistComponent {
groceryList: GroceryItem[] = [];
id: string = '';
product: string = '';
quantity: number = 0;
price: number = 0;
constructor(private groceryListService: GroceryListService) {
this.groceryList = this.groceryListService.getGroceryList();
}
addGrocery(): void {
this.groceryListService.addGrocery(this.id, this.product, this.quantity, this.price);
this.clearForm();
}
clearForm(): void {
this.id = '';
this.product = '';
this.quantity = 0;
this.price = 0;
}
}
OUTPUT:
- Classroom List
// classroomlist.service.ts
import { Injectable } from '@angular/core';
export interface Classroom {
id: string;
room: string;
floor: number;
}
@Injectable({
providedIn: 'root',
})
export class ClassroomListService {
private classroomList: Classroom[] = [];
addClassroom(id: string, room: string, floor: number): void {
this.classroomList.push({ id, room, floor });
}
getClassroomList(): Classroom[] {
return this.classroomList;
}
}
// classroomlist.component.ts
import { Component } from '@angular/core';
import { ClassroomListService, Classroom } from '../services/classroomlist/classroomlist.service';
@Component({
selector: 'app-classroomlist',
templateUrl: './classroomlist.component.html',
styleUrl: './classroomlist.component.css'
})
export class ClassroomlistComponent {
classroomList: Classroom[] = [];
id: string = '';
room: string = '';
floor: number = 0;
constructor(private classroomListService: ClassroomListService) {
this.classroomList = this.classroomListService.getClassroomList();
}
addClassroom(): void {
this.classroomListService.addClassroom(this.id, this.room, this.floor);
this.clearForm();
}
clearForm(): void {
this.id = '';
this.room = '';
this.floor = 0;
}
}
OUTPUT:
- Inventory List
// inventorylist.service.ts
import { Injectable } from '@angular/core';
export interface InventoryItem {
id: string;
product: string;
quantity: number;
}
@Injectable({
providedIn: 'root',
})
export class InventoryListService {
private inventoryList: InventoryItem[] = [];
addInventoryItem(id: string, product: string, quantity: number): void {
this.inventoryList.push({ id, product, quantity });
}
getInventoryList(): InventoryItem[] {
return this.inventoryList;
}
}
// inventorylist.component.ts
import { Component } from '@angular/core';
import { InventoryListService, InventoryItem } from '../services/inventorylist/inventorylist.service';
@Component({
selector: 'app-inventorylist',
templateUrl: './inventorylist.component.html',
styleUrl: './inventorylist.component.css'
})
export class InventorylistComponent {
inventoryList: InventoryItem[] = [];
id: string = '';
product: string = '';
quantity: number = 0;
constructor(private inventoryListService: InventoryListService) {
this.inventoryList = this.inventoryListService.getInventoryList();
}
addInventoryItem(): void {
this.inventoryListService.addInventoryItem(this.id, this.product, this.quantity);
this.clearForm();
}
clearForm(): void {
this.id = '';
this.product = '';
this.quantity = 0;
}
}
OUTPUT:
- Lecture List
// lecturelist.service.ts
import { Injectable } from '@angular/core';
export interface LectureItem {
id: string;
subject: string;
lecture: string;
}
@Injectable({
providedIn: 'root',
})
export class LectureListService {
private lectureList: LectureItem[] = [];
addLectureItem(id: string, subject: string, lecture: string): void {
this.lectureList.push({ id, subject, lecture });
}
getLectureList(): LectureItem[] {
return this.lectureList;
}
}
// lecturelist.component.ts
import { Component } from '@angular/core';
import { LectureListService, LectureItem } from '../services/lecturelist/lecturelist.service';
@Component({
selector: 'app-lecturelist',
templateUrl: './lecturelist.component.html',
styleUrl: './lecturelist.component.css'
})
export class LecturelistComponent {
lectureList: LectureItem[] = [];
id: string = '';
subject: string = '';
lecture: string = '';
constructor(private lectureListService: LectureListService) {
this.lectureList = this.lectureListService.getLectureList();
}
addLectureItem(): void {
this.lectureListService.addLectureItem(this.id, this.subject, this.lecture);
this.clearForm();
}
clearForm(): void {
this.id = '';
this.subject = '';
this.lecture = '';
}
}
OUTPUT:
- Stationery List
// stationerylist.service.ts
import { Injectable } from '@angular/core';
export interface StationeryItem {
id: string;
item: string;
}
@Injectable({
providedIn: 'root',
})
export class StationeryListService {
private stationeryList: StationeryItem[] = [];
addStationeryItem(id: string, item: string): void {
this.stationeryList.push({ id, item });
}
getStationeryList(): StationeryItem[] {
return this.stationeryList;
}
}
// stationerylist.component.ts
import { Component } from '@angular/core';
import { StationeryListService, StationeryItem } from '../services/stationerylist/stationerylist.service';
@Component({
selector: 'app-stationerylist',
templateUrl: './stationerylist.component.html',
styleUrl: './stationerylist.component.css'
})
export class StationerylistComponent {
stationeryList: StationeryItem[] = [];
id: string = '';
item: string = '';
constructor(private stationeryListService: StationeryListService) {
this.stationeryList = this.stationeryListService.getStationeryList();
}
addStationeryItem(): void {
this.stationeryListService.addStationeryItem(this.id, this.item);
this.clearForm();
}
clearForm(): void {
this.id = '';
this.item = '';
}
}
OUTPUT:
- Flower List
// flowerlist.service.ts
import { Injectable } from '@angular/core';
export interface Flower {
id: string;
flower: string;
price: number;
}
@Injectable({
providedIn: 'root',
})
export class FlowerListService {
private flowerList: Flower[] = [];
addFlower(id: string, flower: string, price: number): void {
this.flowerList.push({ id, flower, price });
}
getFlowerList(): Flower[] {
return this.flowerList;
}
}
// flowerlist.component.ts
import { Component } from '@angular/core';
import { FlowerListService, Flower } from '../services/flowerlist/flowerlist.service';
@Component({
selector: 'app-flowerlist',
templateUrl: './flowerlist.component.html',
styleUrl: './flowerlist.component.css'
})
export class FlowerlistComponent {
flowerList: Flower[] = [];
id: string = '';
flower: string = '';
price: number = 0;
constructor(private flowerListService: FlowerListService) {
this.flowerList = this.flowerListService.getFlowerList();
}
addFlower(): void {
this.flowerListService.addFlower(this.id, this.flower, this.price);
this.clearForm();
}
clearForm(): void {
this.id = '';
this.flower = '';
this.price = 0;
}
}
OUTPUT:
- Destination List
// destinationlist.service.ts
import { Injectable } from '@angular/core';
export interface Destination {
id: string;
destination: string;
location: string;
entrancePrice: number;
}
@Injectable({
providedIn: 'root',
})
export class DestinationListService {
private destinationList: Destination[] = [];
addDestination(id: string, destination: string, location: string, entrancePrice: number): void {
this.destinationList.push({ id, destination, location, entrancePrice });
}
getDestinationList(): Destination[] {
return this.destinationList;
}
}
// destinationlist.component.ts
import { Component } from '@angular/core';
import { DestinationListService, Destination } from '../services/destinationlist/destinationlist.service';
@Component({
selector: 'app-destinationlist',
templateUrl: './destinationlist.component.html',
styleUrl: './destinationlist.component.css'
})
export class DestinationlistComponent {
destinationList: Destination[] = [];
id: string = '';
destination: string = '';
location: string = '';
entrancePrice: number = 0;
constructor(private destinationListService: DestinationListService) {
this.destinationList = this.destinationListService.getDestinationList();
}
addDestination(): void {
this.destinationListService.addDestination(this.id, this.destination, this.location, this.entrancePrice);
this.clearForm();
}
clearForm(): void {
this.id = '';
this.destination = '';
this.location = '';
this.entrancePrice = 0;
}
}
OUTPUT:
- Laptop List
// laptoplist.service.ts
import { Injectable } from '@angular/core';
export interface Laptop {
id: string;
laptop: string;
price: number;
}
@Injectable({
providedIn: 'root',
})
export class LaptopListService {
private laptopList: Laptop[] = [];
addLaptop(id: string, laptop: string, price: number): void {
this.laptopList.push({ id, laptop, price });
}
getLaptopList(): Laptop[] {
return this.laptopList;
}
}
// laptoplist.component.ts
import { Component } from '@angular/core';
import { LaptopListService, Laptop } from '../services/laptoplist/laptoplist.service';
@Component({
selector: 'app-laptoplist',
templateUrl: './laptoplist.component.html',
styleUrl: './laptoplist.component.css'
})
export class LaptoplistComponent {
laptopList: Laptop[] = [];
id: string = '';
laptop: string = '';
price: number = 0;
constructor(private laptopListService: LaptopListService) {
this.laptopList = this.laptopListService.getLaptopList();
}
addLaptop(): void {
this.laptopListService.addLaptop(this.id, this.laptop, this.price);
this.clearForm();
}
clearForm(): void {
this.id = '';
this.laptop = '';
this.price = 0;
}
}
OUTPUT:
- Laptop Specification List
// laptopspecificationlist.service.ts
import { Injectable } from '@angular/core';
export interface LaptopSpecification {
id: string;
laptop: string;
specs: string;
price: number;
}
@Injectable({
providedIn: 'root',
})
export class LaptopSpecificationListService {
private laptopSpecificationList: LaptopSpecification[] = [];
addLaptopSpecification(id: string, laptop: string, specs: string, price: number): void {
this.laptopSpecificationList.push({ id, laptop, specs, price });
}
getLaptopSpecificationList(): LaptopSpecification[] {
return this.laptopSpecificationList;
}
}
// laptopspecificationlist.component.ts
import { Component } from '@angular/core';
import { LaptopSpecificationListService, LaptopSpecification } from '../services/laptopspecificationlist/laptopspecificationlist.service';
@Component({
selector: 'app-laptopspecificationslist',
templateUrl: './laptopspecificationslist.component.html',
styleUrl: './laptopspecificationslist.component.css'
})
export class LaptopspecificationslistComponent {
laptopSpecificationList: LaptopSpecification[] = [];
id: string = '';
laptop: string = '';
specs: string = '';
price: number = 0;
constructor(private laptopSpecificationListService: LaptopSpecificationListService) {
this.laptopSpecificationList = this.laptopSpecificationListService.getLaptopSpecificationList();
}
addLaptopSpecification(): void {
this.laptopSpecificationListService.addLaptopSpecification(this.id, this.laptop, this.specs, this.price);
this.clearForm();
}
clearForm(): void {
this.id = '';
this.laptop = '';
this.specs = '';
this.price = 0;
}
}
OUTPUT:
- Computer Hardware List
// computerhardwarelist.service.ts
import { Injectable } from '@angular/core';
export interface ComputerHardware {
id: string;
hardware: string;
descriptions: string;
price: number;
}
@Injectable({
providedIn: 'root',
})
export class ComputerHardwareListService {
private computerHardwareList: ComputerHardware[] = [];
addComputerHardware(id: string, hardware: string, descriptions: string, price: number): void {
this.computerHardwareList.push({ id, hardware, descriptions, price });
}
getComputerHardwareList(): ComputerHardware[] {
return this.computerHardwareList;
}
}
// computerhardwarelist.component.ts
import { Component } from '@angular/core';
import { ComputerHardwareListService, ComputerHardware } from '../services/computerhardwarelist/computerhardwarelist.service';
@Component({
selector: 'app-computerhardwarelist',
templateUrl: './computerhardwarelist.component.html',
styleUrl: './computerhardwarelist.component.css'
})
export class ComputerhardwarelistComponent {
computerHardwareList: ComputerHardware[] = [];
id: string = '';
hardware: string = '';
descriptions: string = '';
price: number = 0;
constructor(private computerHardwareListService: ComputerHardwareListService) {
this.computerHardwareList = this.computerHardwareListService.getComputerHardwareList();
}
addComputerHardware(): void {
this.computerHardwareListService.addComputerHardware(this.id, this.hardware, this.descriptions, this.price);
this.clearForm();
}
clearForm(): void {
this.id = '';
this.hardware = '';
this.descriptions = '';
this.price = 0;
}
}
OUTPUT:
- Mobile App List
// mobileapplist.service.ts
import { Injectable } from '@angular/core';
export interface MobileApp {
id: string;
app: string;
descriptions: string;
}
@Injectable({
providedIn: 'root',
})
export class MobileAppListService {
private mobileAppList: MobileApp[] = [];
addMobileApp(id: string, app: string, descriptions: string): void {
this.mobileAppList.push({ id, app, descriptions });
}
getMobileAppList(): MobileApp[] {
return this.mobileAppList;
}
}
// mobileapplist.component.ts
import { Component } from '@angular/core';
import { MobileAppListService, MobileApp } from '../services/mobileapplist/mobileapplist.service';
@Component({
selector: 'app-mobileapplist',
templateUrl: './mobileapplist.component.html',
styleUrl: './mobileapplist.component.css'
})
export class MobileapplistComponent {
mobileAppList: MobileApp[] = [];
id: string = '';
app: string = '';
descriptions: string = '';
constructor(private mobileAppListService: MobileAppListService) {
this.mobileAppList = this.mobileAppListService.getMobileAppList();
}
addMobileApp(): void {
this.mobileAppListService.addMobileApp(this.id, this.app, this.descriptions);
this.clearForm();
}
clearForm(): void {
this.id = '';
this.app = '';
this.descriptions = '';
}
}
OUTPUT:
- Video List
// videolist.service.ts
import { Injectable } from '@angular/core';
export interface Video {
id: string;
video: string;
descriptions: string;
}
@Injectable({
providedIn: 'root',
})
export class VideoListService {
private videoList: Video[] = [];
addVideo(id: string, video: string, descriptions: string): void {
this.videoList.push({ id, video, descriptions });
}
getVideoList(): Video[] {
return this.videoList;
}
}
// videolist.component.ts
import { Component } from '@angular/core';
import { VideoListService, Video } from '../services/videolist/videolist.service';
@Component({
selector: 'app-videolist',
templateUrl: './videolist.component.html',
styleUrl: './videolist.component.css'
})
export class VideolistComponent {
videoList: Video[] = [];
id: string = '';
video: string = '';
descriptions: string = '';
constructor(private videoListService: VideoListService) {
this.videoList = this.videoListService.getVideoList();
}
addVideo(): void {
this.videoListService.addVideo(this.id, this.video, this.descriptions);
this.clearForm();
}
clearForm(): void {
this.id = '';
this.video = '';
this.descriptions = '';
}
}
OUTPUT:
- Tv Show List
// tvshowlist.service.ts
import { Injectable } from '@angular/core';
export interface TVShow {
id: string;
showname: string;
channel: string;
parentalGuidance: string;
}
@Injectable({
providedIn: 'root',
})
export class TVShowListService {
private tvShowList: TVShow[] = [];
addShow(id: string, showname: string, channel: string, parentalGuidance: string): void {
this.tvShowList.push({ id, showname, channel, parentalGuidance });
}
getTVShowList(): TVShow[] {
return this.tvShowList;
}
}
// tvshowlist.component.ts
import { Component } from '@angular/core';
import { TVShowListService, TVShow } from '../services/tvshowlist/tvshowlist.service';
@Component({
selector: 'app-tvshowlist',
templateUrl: './tvshowlist.component.html',
styleUrl: './tvshowlist.component.css'
})
export class TvshowlistComponent {
tvShowList: TVShow[] = [];
id: string = '';
showname: string = '';
channel: string = '';
parentalGuidance: string = '';
constructor(private tvShowListService: TVShowListService) {
this.tvShowList = this.tvShowListService.getTVShowList();
}
addShow(): void {
this.tvShowListService.addShow(this.id, this.showname, this.channel, this.parentalGuidance);
this.clearForm();
}
clearForm(): void {
this.id = '';
this.showname = '';
this.channel = '';
this.parentalGuidance = '';
}
}
OUTPUT:
- Furniture List
// furniturelist.service.ts
import { Injectable } from '@angular/core';
export interface Furniture {
id: string;
furniturename: string;
woodtype: string;
price: number;
}
@Injectable({
providedIn: 'root',
})
export class FurnitureListService {
private furnitureList: Furniture[] = [];
addFurniture(id: string, furniturename: string, woodtype: string, price: number): void {
this.furnitureList.push({ id, furniturename, woodtype, price });
}
getFurnitureList(): Furniture[] {
return this.furnitureList;
}
}
// furniturelist.component.ts
import { Component } from '@angular/core';
import { FurnitureListService, Furniture } from '../services/furniturelist/furniturelist.service';
@Component({
selector: 'app-furniturelist',
templateUrl: './furniturelist.component.html',
styleUrl: './furniturelist.component.css'
})
export class FurniturelistComponent {
furnitureList: Furniture[] = [];
id: string = '';
furniturename: string = '';
woodtype: string = '';
price: number = 0;
constructor(private furnitureListService: FurnitureListService) {
this.furnitureList = this.furnitureListService.getFurnitureList();
}
addFurniture(): void {
this.furnitureListService.addFurniture(this.id, this.furniturename, this.woodtype, this.price);
this.clearForm();
}
clearForm(): void {
this.id = '';
this.furniturename = '';
this.woodtype = '';
this.price = 0;
}
}
OUTPUT:
- Accessory List
// accessorylist.service.ts
import { Injectable } from '@angular/core';
export interface Accessory {
id: string;
accessory: string;
brand: string;
price: number;
}
@Injectable({
providedIn: 'root',
})
export class AccessoryListService {
private accessoryList: Accessory[] = [];
addAccessory(id: string, accessory: string, brand: string, price: number): void {
this.accessoryList.push({ id, accessory, brand, price });
}
getAccessoryList(): Accessory[] {
return this.accessoryList;
}
}
// accessorylist.component.ts
import { Component } from '@angular/core';
import { AccessoryListService, Accessory } from '../services/accessorylist/accessorylist.service';
@Component({
selector: 'app-accessorylist',
templateUrl: './accessorylist.component.html',
styleUrl: './accessorylist.component.css'
})
export class AccessorylistComponent {
accessoryList: Accessory[] = [];
id: string = '';
accessory: string = '';
brand: string = '';
price: number = 0;
constructor(private accessoryListService: AccessoryListService) {
this.accessoryList = this.accessoryListService.getAccessoryList();
}
addAccessory(): void {
this.accessoryListService.addAccessory(this.id, this.accessory, this.brand, this.price);
this.clearForm();
}
clearForm(): void {
this.id = '';
this.accessory = '';
this.brand = '';
this.price = 0;
}
}
OUTPUT:
- Building List
// buildinglist.service.ts
import { Injectable } from '@angular/core';
export interface BuildingList {
id: string;
buildingname: string;
location: string;
}
@Injectable({
providedIn: 'root',
})
export class BuildingListService {
private buildings: BuildingList[] = [];
addBuilding(id: string, buildingname: string, location: string): void {
this.buildings.push({
id,
buildingname,
location
});
}
getBuildings(): BuildingList[] {
return this.buildings;
}
}
// buildinglist.component.ts
import { Component } from '@angular/core';
import { BuildingListService, BuildingList } from '../services/buildinglist/buildinglist.service';
@Component({
selector: 'app-buildinglist',
templateUrl: './buildinglist.component.html',
styleUrl: './buildinglist.component.css'
})
export class BuildinglistComponent {
buildings: BuildingList[] = [];
id: string = '';
buildingname: string = '';
location: string = '';
constructor(private buildingListService: BuildingListService) {
this.buildings = this.buildingListService.getBuildings();
}
addBuilding(): void {
this.buildingListService.addBuilding(this.id, this.buildingname, this.location);
this.clearForm();
}
clearForm(): void {
this.id = '';
this.buildingname = '';
this.location = '';
}
}
OUTPUT:
- Painting List
// paintinglist.service.ts
import { Injectable } from '@angular/core';
export interface PaintingList {
id: string;
artname: string;
artist: string;
}
@Injectable({
providedIn: 'root',
})
export class PaintingListService {
private paintings: PaintingList[] = [];
addPainting(id: string, artname: string, artist: string): void {
this.paintings.push({
id,
artname,
artist
});
}
getPaintings(): PaintingList[] {
return this.paintings;
}
}
// paintinglist.component.ts
import { Component } from '@angular/core';
import { PaintingListService, PaintingList } from '../services/paintinglist/paintinglist.service';
@Component({
selector: 'app-paintinglist',
templateUrl: './paintinglist.component.html',
styleUrl: './paintinglist.component.css'
})
export class PaintinglistComponent {
paintings: PaintingList[] = [];
id: string = '';
artname: string = '';
artist: string = '';
constructor(private paintingListService: PaintingListService) {
this.paintings = this.paintingListService.getPaintings();
}
addPainting(): void {
this.paintingListService.addPainting(this.id, this.artname, this.artist);
this.clearForm();
}
clearForm(): void {
this.id = '';
this.artname = '';
this.artist = '';
}
}
OUTPUT:
- Artist List
// artistlist.service.ts
import { Injectable } from '@angular/core';
export interface ArtistList {
id: string;
artist: string;
gender: string;
}
@Injectable({
providedIn: 'root',
})
export class ArtistListService {
private artists: ArtistList[] = [];
addArtist(id: string, artist: string, gender: string): void {
this.artists.push({
id,
artist,
gender
});
}
getArtists(): ArtistList[] {
return this.artists;
}
}
// artistlist.component.ts
import { Component } from '@angular/core';
import { ArtistListService, ArtistList } from '../services/artistlist/artistlist.service';
@Component({
selector: 'app-artistlist',
templateUrl: './artistlist.component.html',
styleUrl: './artistlist.component.css'
})
export class ArtistlistComponent {
artists: ArtistList[] = [];
id: string = '';
artist: string = '';
gender: string = '';
constructor(private artistListService: ArtistListService) {
this.artists = this.artistListService.getArtists();
}
addArtist(): void {
this.artistListService.addArtist(this.id, this.artist, this.gender);
this.clearForm();
}
clearForm(): void {
this.id = '';
this.artist = '';
this.gender = '';
}
}
OUTPUT:
- Composer List
// composerlist.service.ts
import { Injectable } from '@angular/core';
export interface ComposerList {
id: string;
composer: string;
gender: string;
}
@Injectable({
providedIn: 'root',
})
export class ComposerListService {
private composers: ComposerList[] = [];
addComposer(id: string, composer: string, gender: string): void {
this.composers.push({
id,
composer,
gender
});
}
getComposers(): ComposerList[] {
return this.composers;
}
}
// composerlist.component.ts
import { Component } from '@angular/core';
import { ComposerListService, ComposerList } from '../services/composerlist/composerlist.service';
@Component({
selector: 'app-composerlist',
templateUrl: './composerlist.component.html',
styleUrl: './composerlist.component.css'
})
export class ComposerlistComponent {
composers: ComposerList[] = [];
id: string = '';
composer: string = '';
gender: string = '';
constructor(private composerListService: ComposerListService) {
this.composers = this.composerListService.getComposers();
}
addComposer(): void {
this.composerListService.addComposer(this.id, this.composer, this.gender);
this.clearForm();
}
clearForm(): void {
this.id = '';
this.composer = '';
this.gender = '';
}
}
OUTPUT:
- Podcast List
// podcastlist.service.ts
import { Injectable } from '@angular/core';
export interface PodcastList {
id: string;
contentCreator: string;
description: string;
}
@Injectable({
providedIn: 'root',
})
export class PodcastListService {
private podcasts: PodcastList[] = [];
addPodcast(id: string, contentCreator: string, description: string): void {
this.podcasts.push({
id,
contentCreator,
description
});
}
getPodcasts(): PodcastList[] {
return this.podcasts;
}
}
// podcastlist.component.ts
import { Component } from '@angular/core';
import { PodcastListService, PodcastList } from '../services/podcastlist/podcastlist.service';
@Component({
selector: 'app-podcastlist',
templateUrl: './podcastlist.component.html',
styleUrl: './podcastlist.component.css'
})
export class PodcastlistComponent {
podcasts: PodcastList[] = [];
id: string = '';
contentCreator: string = '';
description: string = '';
constructor(private podcastListService: PodcastListService) {
this.podcasts = this.podcastListService.getPodcasts();
}
addPodcast(): void {
this.podcastListService.addPodcast(this.id, this.contentCreator, this.description);
this.clearForm();
}
clearForm(): void {
this.id = '';
this.contentCreator = '';
this.description = '';
}
}
OUTPUT:
- Exercise List
// exerciselist.service.ts
import { Injectable } from '@angular/core';
export interface ExerciseList {
id: string;
exerciseName: string;
description: string;
targetMuscle: string;
}
@Injectable({
providedIn: 'root',
})
export class ExerciseListService {
private exercises: ExerciseList[] = [];
addExercise(id: string, exerciseName: string, description: string, targetMuscle: string): void {
this.exercises.push({
id,
exerciseName,
description,
targetMuscle
});
}
getExercises(): ExerciseList[] {
return this.exercises;
}
}
// exerciselist.component.ts
import { Component } from '@angular/core';
import { ExerciseListService, ExerciseList } from '../services/exerciselist/exerciselist.service';
@Component({
selector: 'app-exerciselist',
templateUrl: './exerciselist.component.html',
styleUrl: './exerciselist.component.css'
})
export class ExerciselistComponent {
exercises: ExerciseList[] = [];
id: string = '';
exerciseName: string = '';
description: string = '';
targetMuscle: string = '';
constructor(private exerciseListService: ExerciseListService) {
this.exercises = this.exerciseListService.getExercises();
}
addExercise(): void {
this.exerciseListService.addExercise(this.id, this.exerciseName, this.description, this.targetMuscle);
this.clearForm();
}
clearForm(): void {
this.id = '';
this.exerciseName = '';
this.description = '';
this.targetMuscle = '';
}
}
OUTPUT:
- Meal Plan List
// mealplanlist.service.ts
import { Injectable } from '@angular/core';
export interface MealPlanList {
id: string;
foodName: string;
day: string;
mealType: string;
}
@Injectable({
providedIn: 'root',
})
export class MealPlanListService {
private mealPlans: MealPlanList[] = [];
addMealPlan(id: string, foodName: string, day: string, mealType: string): void {
this.mealPlans.push({
id,
foodName,
day,
mealType
});
}
getMealPlans(): MealPlanList[] {
return this.mealPlans;
}
}
// mealplanlist.component.ts
import { Component } from '@angular/core';
import { MealPlanListService, MealPlanList } from '../services/mealplanlist/mealplanlist.service';
@Component({
selector: 'app-mealplanlist',
templateUrl: './mealplanlist.component.html',
styleUrl: './mealplanlist.component.css'
})
export class MealplanlistComponent {
mealPlans: MealPlanList[] = [];
id: string = '';
foodName: string = '';
day: string = '';
mealType: string = '';
constructor(private mealPlanListService: MealPlanListService) {
this.mealPlans = this.mealPlanListService.getMealPlans();
}
addMealPlan(): void {
this.mealPlanListService.addMealPlan(this.id, this.foodName, this.day, this.mealType);
this.clearForm();
}
clearForm(): void {
this.id = '';
this.foodName = '';
this.day = '';
this.mealType = '';
}
}
OUTPUT:
- Budget List
// budgetlist.service.ts
import { Injectable } from '@angular/core';
export interface BudgetList {
id: string;
amount: number;
day: string;
}
@Injectable({
providedIn: 'root',
})
export class BudgetListService {
private budgets: BudgetList[] = [];
addBudget(id: string, amount: number, day: string): void {
this.budgets.push({
id,
amount,
day
});
}
getBudgets(): BudgetList[] {
return this.budgets;
}
}
// budgetlist.component.ts
import { Component } from '@angular/core';
import { BudgetListService, BudgetList } from '../services/budgetlist/budgetlist.service';
@Component({
selector: 'app-budgetlist',
templateUrl: './budgetlist.component.html',
styleUrl: './budgetlist.component.css'
})
export class BudgetlistComponent {
budgets: BudgetList[] = [];
id: string = '';
amount: number = 0;
day: string = '';
constructor(private budgetListService: BudgetListService) {
this.budgets = this.budgetListService.getBudgets();
}
addBudget(): void {
this.budgetListService.addBudget(this.id, this.amount, this.day);
this.clearForm();
}
clearForm(): void {
this.id = '';
this.amount = 0;
this.day = '';
}
}
OUTPUT:
- Presentation List
// presentationlist.service.ts
import { Injectable } from '@angular/core';
export interface PresentationList {
id: string;
title: string;
softwareTool: string;
}
@Injectable({
providedIn: 'root',
})
export class PresentationListService {
private presentations: PresentationList[] = [];
addPresentation(id: string, title: string, softwareTool: string): void {
this.presentations.push({
id,
title,
softwareTool
});
}
getPresentations(): PresentationList[] {
return this.presentations;
}
}
// presentationlist.component.ts
import { Component } from '@angular/core';
import { PresentationListService, PresentationList } from '../services/presentationlist/presentationlist.service';
@Component({
selector: 'app-presentationlist',
templateUrl: './presentationlist.component.html',
styleUrl: './presentationlist.component.css'
})
export class PresentationlistComponent {
presentations: PresentationList[] = [];
id: string = '';
title: string = '';
softwareTool: string = '';
constructor(private presentationListService: PresentationListService) {
this.presentations = this.presentationListService.getPresentations();
}
addPresentation(): void {
this.presentationListService.addPresentation(this.id, this.title, this.softwareTool);
this.clearForm();
}
clearForm(): void {
this.id = '';
this.title = '';
this.softwareTool = '';
}
}
OUTPUT:
- Tour List
// tourlist.service.ts
import { Injectable } from '@angular/core';
export interface TourList {
id: string;
tour: string;
location: string;
}
@Injectable({
providedIn: 'root',
})
export class TourListService {
private tours: TourList[] = [];
addTour(id: string, tour: string, location: string): void {
this.tours.push({
id,
tour,
location
});
}
getTours(): TourList[] {
return this.tours;
}
}
// tourlist.component.ts
import { Component } from '@angular/core';
import { TourListService, TourList } from '../services/tourlist/tourlist.service';
@Component({
selector: 'app-tourlist',
templateUrl: './tourlist.component.html',
styleUrl: './tourlist.component.css'
})
export class TourlistComponent {
tours: TourList[] = [];
id: string = '';
tour: string = '';
location: string = '';
constructor(private tourListService: TourListService) {
this.tours = this.tourListService.getTours();
}
addTour(): void {
this.tourListService.addTour(this.id, this.tour, this.location);
this.clearForm();
}
clearForm(): void {
this.id = '';
this.tour = '';
this.location = '';
}
}
OUTPUT:
- Event List
// eventlist.service.ts
import { Injectable } from '@angular/core';
export interface EventList {
id: string;
event: string;
location: string;
}
@Injectable({
providedIn: 'root',
})
export class EventListService {
private events: EventList[] = [];
addEvent(id: string, event: string, location: string): void {
this.events.push({
id,
event,
location
});
}
getEvents(): EventList[] {
return this.events;
}
}
// eventlist.component.ts
import { Component } from '@angular/core';
import { EventListService, EventList } from '../services/eventlist/eventlist.service';
@Component({
selector: 'app-eventlist',
templateUrl: './eventlist.component.html',
styleUrl: './eventlist.component.css'
})
export class EventlistComponent {
events: EventList[] = [];
id: string = '';
event: string = '';
location: string = '';
constructor(private eventListService: EventListService) {
this.events = this.eventListService.getEvents();
}
addEvent(): void {
this.eventListService.addEvent(this.id, this.event, this.location);
this.clearForm();
}
clearForm(): void {
this.id = '';
this.event = '';
this.location = '';
}
}
OUTPUT:
- Developer Tool List
// developerlist.service.ts
import { Injectable } from '@angular/core';
export interface DeveloperList {
id: string;
softwareTool: string;
version: string;
}
@Injectable({
providedIn: 'root',
})
export class DeveloperListService {
private developers: DeveloperList[] = [];
addDeveloper(id: string, softwareTool: string, version: string): void {
this.developers.push({
id,
softwareTool,
version
});
}
getDevelopers(): DeveloperList[] {
return this.developers;
}
}
// developerlist.component.ts
import { Component } from '@angular/core';
import { DeveloperListService, DeveloperList } from '../services/developerlist/developerlist.service';
@Component({
selector: 'app-developertoolslist',
templateUrl: './developertoolslist.component.html',
styleUrl: './developertoolslist.component.css'
})
export class DevelopertoolslistComponent {
developers: DeveloperList[] = [];
id: string = '';
softwareTool: string = '';
version: string = '';
constructor(private developerListService: DeveloperListService) {
this.developers = this.developerListService.getDevelopers();
}
addDeveloper(): void {
this.developerListService.addDeveloper(this.id, this.softwareTool, this.version);
this.clearForm();
}
clearForm(): void {
this.id = '';
this.softwareTool = '';
this.version = '';
}
}
OUTPUT:
- Framework List
// frameworklist.service.ts
import { Injectable } from '@angular/core';
export interface FrameworkList {
id: string;
framework: string;
version: string;
}
@Injectable({
providedIn: 'root',
})
export class FrameworkListService {
private frameworks: FrameworkList[] = [];
addFramework(id: string, framework: string, version: string): void {
this.frameworks.push({
id,
framework,
version
});
}
getFrameworks(): FrameworkList[] {
return this.frameworks;
}
}
// frameworklist.component.ts
import { Component } from '@angular/core';
import { FrameworkListService, FrameworkList } from '../services/frameworklist/frameworklist.service';
@Component({
selector: 'app-frameworklist',
templateUrl: './frameworklist.component.html',
styleUrl: './frameworklist.component.css'
})
export class FrameworklistComponent {
frameworks: FrameworkList[] = [];
id: string = '';
framework: string = '';
version: string = '';
constructor(private frameworkListService: FrameworkListService) {
this.frameworks = this.frameworkListService.getFrameworks();
}
addFramework(): void {
this.frameworkListService.addFramework(this.id, this.framework, this.version);
this.clearForm();
}
clearForm(): void {
this.id = '';
this.framework = '';
this.version = '';
}
}
OUTPUT:
- Library List
// librarylist.service.ts
import { Injectable } from '@angular/core';
export interface LibraryList {
id: string;
libraryName: string;
opening: string;
closing: string;
}
@Injectable({
providedIn: 'root',
})
export class LibraryListService {
private libraries: LibraryList[] = [];
addLibrary(id: string, libraryName: string, opening: string, closing: string): void {
this.libraries.push({
id,
libraryName,
opening,
closing
});
}
getLibraries(): LibraryList[] {
return this.libraries;
}
}
// librarylist.component.ts
import { Component } from '@angular/core';
import { LibraryListService, LibraryList } from '../services/librarylist/librarylist.service';
@Component({
selector: 'app-librarylist',
templateUrl: './librarylist.component.html',
styleUrl: './librarylist.component.css'
})
export class LibrarylistComponent {
libraries: LibraryList[] = [];
id: string = '';
libraryName: string = '';
opening: string = '';
closing: string = '';
constructor(private libraryListService: LibraryListService) {
this.libraries = this.libraryListService.getLibraries();
}
addLibrary(): void {
this.libraryListService.addLibrary(this.id, this.libraryName, this.opening, this.closing);
this.clearForm();
}
clearForm(): void {
this.id = '';
this.libraryName = '';
this.opening = '';
this.closing = '';
}
}
OUTPUT:
Github Link:
https://github.com/Walterific/Research-Angular-Services.git
Hosting URL Link:
https://research-angular-services.web.app/
References:
https://v17.angular.io/guide/architecture-services
Subscribe to my newsletter
Read articles from Walter Mark B. Inductivo Jr. directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Walter Mark B. Inductivo Jr.
Walter Mark B. Inductivo Jr.
Watch Me Whip 👊, Watch Me Nae-Nae 🖐️