Agular Questions
Agular Questions
Your task is to create a web application that demonstrates the use of Angular's
HttpClient module for communication with a backend API. The application simulates
managing a collection of Storage Houses, allowing users to retrieve existing storage
houses, add new ones, edit them, and view their details.
Backend API:
The backend API is a mock JSON server that provides storage house data to the
frontend. It offers the following:
Endpoints:
Note:
The JSON server URL is defined in the StorageHouseService class. Ensure the backend
is running while testing the application.
Implementation Guidelines:
Model (storage-house.model.ts):
typescript
CopyEdit
id?: number;
name: string;
location: string;
capacity: number;
commodityType: string;
operationalStatus: string;
constructionDate: string;
lastInspectionDate: string;
temperatureControl: string;
Service (storage-house.service.ts):
Functions to Implement:
Additional Notes:
• Declare a public property backendUrl to store the base URL for the API:
typescript
CopyEdit
backendUrl = '{your-portal-url}/proxy/3001/storage-houses';
This component implements a form for adding a new storage house using Angular's
Reactive Forms, bound to the storageHouseForm instance. The ngSubmit() directive
links the form submission event to the onSubmit() method.
Form Fields:
1. Storage House Name: Input type text with a placeholder "Enter storage house
name" and required validation.
2. Location: Input type text with a placeholder "Enter location" and required
validation.
3. Capacity: Input type number with a placeholder "Enter capacity (tons)" and a
minimum value validation (greater than 0).
Submit Button:
• Type: Submit.
• The form structure should match the Add Storage House Component but pre-
filled with the current details of the selected storage house.
• Submit Button:
This component manages the list of storage houses, allowing functionalities for
fetching, sorting, and editing data.
Properties:
1. storageHouses: An array to hold the list of storage house objects fetched from
the backend.
3. sortOrder: A string ('asc' or 'desc') managing the sorting order of storage houses
by capacity.
Methods:
Table Layout:
1. Headers:
o Name
o Location
o Capacity (tons)
o Commodity Type
o Operational Status
o Action
2. Rows:
3. Actions Column:
Loading Indicator:
QUESTION 2:
Your task is to create a web application that demonstrates the use of Angular's
HTTPClient module for communication with mock data. The application will simulate
managing textile products, allowing users to retrieve a list of products, add new ones,
and delete them using HTTP requests.
Static Data Mock: A JSON Server that provides static data to the frontend. It should
offer the following endpoints:
• GET /fabrics: This endpoint will return a list of static textile product details in
JSON format.
Frontend (Angular): You will build an Angular application to interact with the mock data
via HTTPClient services. The frontend should include the following features:
Model (fabric.model.ts):
id?: number;
fabricNumber: string;
name: string;
price: number;
productionTime: number;
TextileService (services/textile.service.ts):
• Declare a private property backendUrl to store the base URL for the API.
Example: backendUrl = '{your-portal-url}/proxy/3001/fabrics';
• getFabrics(): Makes an HTTP GET request to retrieve a list of textile products and
returns an Observable that emits an array of TextileProduct objects.
• addFabric(): Makes an HTTP POST request to add a new textile product. It takes
a TextileProduct object as a parameter and returns an Observable that emits the
added TextileProduct object.
• This method checks if the form is valid. If so, it calls the addFabric method from
the TextileService to make an HTTP request to add the product.
• Use fabricForm as the property for the FormGroup, which is utilized to manage
the form's state and validation.
Validation Messages:
• "Fabric number must be 5 characters (letters and numbers)" if the fabric number
doesn’t match the pattern.
• "Fabric name must be between 3 and 50 characters" if the name length is invalid.
• "Price must be greater than 0" if the price is less than 0.01.
• "Production time must be at least 1 minute" if the production time is less than 1
minute.
Use the constructor to inject FormBuilder, TextileService, and Router.
Upon successful addition, the user is redirected to the product list page (/fabrics).
Form Fields:
• Fabric Number:
o Bound to formControlName="fabricNumber"
• Fabric Name:
o Bound to formControlName="name"
• Category:
o Bound to formControlName="category"
• Price:
o Bound to formControlName="price"
• Production Time:
• Status:
o Bound to formControlName="status"
• Submit Button:
o Type: submit
Properties:
• sortOrder: A string property (asc or desc), managing the sorting direction of the
product list.
• filterText: A string property used for searching products by fabric number, name,
or category.
• getFabrics(): Makes an HTTP GET request to retrieve textile products from the
TextileService.
Filter Input: At the top of the table, an input field is provided to filter products by fabric
number, name, or category.
Sort Button: Below the filter input, a button is provided to trigger the sortFabrics()
method, allowing users to sort by production time in ascending or descending order.
• The table headers are defined in <thead>, with column labels inside <th> tags in
a single <tr>.
• The price column uses Angular’s number pipe to format the value to two decimal
places.
• The status column uses Angular’s [ngClass] directive to apply CSS classes
(available, out-of-stock, coming-soon) based on the product status.
Textile Form
The Add Textile Form is designed to allow users to input textile product details and
submit them. It uses Angular Reactive Forms (fabricForm) and includes the following
fields:
• Fabric Number:
o Bound to formControlName="fabricNumber"
• Fabric Name:
• Category:
o Bound to formControlName="category"
• Price:
o Bound to formControlName="price"
• Production Time:
o Bound to formControlName="productionTime"
• Status:
o Bound to formControlName="status"
o Type: submit
QUESTION 3:
Your task is to create a web application that demonstrates the use of Angular's
HttpClient module for communication with a backend API. The application simulates
managing a collection of Pharmaceuticals, allowing users to retrieve existing
medicines, add new ones, edit medicines, and view specific medicine details.
Backend API:
The backend API is a mock JSON server that provides pharmaceutical data to the
frontend. It offers the following:
Endpoints:
Note:
The JSON server URL is defined in the MedicineService class. Ensure the backend is
running while testing the application.
Implementation Guidelines:
• Define an interface for the Medicine model encapsulating its attributes in the
model folder.
Frontend (Angular):
You will build an Angular application to interact with the backend API via HttpClient
services. The frontend should include the following features:
Model:
Model (medicine.model.ts):
id?: number;
name: string;
genericName: string;
uses: string[];
sideEffects: string[];
Service (medicine.service.ts):
Services:
medicine.service.ts:
Method Implementations:
• addMedicine():
• getMedicines():
• getMedicineById():
• updateMedicine():
The form is submitted via the onSubmit() method. If the form is valid, it calls
MedicineService.addMedicine() to send the data to the backend.
Upon successful submission, the user is redirected to the medicines list page
(/medicines), and the form is reset.
Purpose:
Form Handling:
• Fields:
o Submit Button: The submit button is placed inside the last <tr> in the
<table>. It is labeled "Add Medicine" and is disabled when the form is
invalid.
Form Layout:
The form structure should mirror the layout of Add Medicine Component. All fields
should display the medicine's current details to allow editing.
Submit Button:
The submit button is positioned in the last <tr> of the table and labeled 'Update
Medicine'.
Functionality:
Properties:
• medicines: An array to hold the list of medicine objects fetched from the
backend.
Methods:
• getMedicines(): Makes an HTTP GET request to fetch all the medicines from the
backend using the MedicineService and populates the medicines array.
The Add Medicine form (medicineForm) is structured using a <table>, with rows (<tr>)
and columns (<td>) defining the layout for input fields and their labels.
Form Details:
• Input Fields:
• Submit Button: The submit button is placed inside the last <tr> in the <table>. It
is labeled "Add Medicine" and is disabled when the form is invalid.
Purpose:
Features:
o Name
o Generic Name
o Uses
o Dosage Form
o Side Effects
o Action
Edit Button:
• Add a button for each medicine to edit its details, which navigates to the Edit
Medicine page.
Loading Indicator:
Backend API:
The backend API is a mock JSON server that provides species data to the frontend. It
offers the following:
Endpoint:
Note: The JSON server URL is defined in the WildlifeService class. Ensure the backend is
running while testing the application.
Implementation Guidelines:
• Define an interface for the Wildlife model encapsulating its attributes in the
model folder.
Frontend (Angular):
You will build an Angular application to interact with the backend API via HttpClient
services. The frontend should include the following features:
Model:
id?: number;
name: string;
habitat: string;
diet: string;
conservationStatus: string;
population: number;
lastSighted: string;
Services:
wildlife.service.ts:
• Use the method name addSpecies() for POST and getSpecies() for GET in
WildlifeService.
• Declare a public property backendUrl to store the base URL for the API:
backendUrl = '{your-portal-url}/proxy/3001/species';
Components:
Method Workflow:
• The form is submitted via the onSubmit() method. If the form is valid, it calls
WildlifeService.addSpecies() to send the data to the backend.
Purpose:
Form Handling:
Fields:
Submission:
• When the form is submitted and valid, a POST request is sent to the backend to
add the species details. Upon successful addition, the form resets and the user
is redirected to the species list page.
Method Workflow:
• The form is submitted via the onSubmit() method. If the form is valid, it calls
WildlifeService.updateSpecies() to send the data to the backend.
• Upon successful submission, the user is redirected to the species list page
(/species), and the form resets.
Purpose:
Form Handling:
• Fields: Same fields and validation as per the Add Species form.
• Submission: When the form is submitted, if valid, a PUT request is sent to the
backend to update the species details. Upon successful update, the user is
redirected to the species list page.
Purpose:
Methods:
Features:
• Display a table with columns for Name, Habitat, Diet, Conservation Status,
Population, Last Sighted, Action.
• Add a button for each species to edit its details, which navigates to the Edit
Species page.
• The Add Species Component form is structured using <table>, with rows (<tr>)
and columns (<td>) defining the layout for input fields and their labels.
Form Details:
Form Initialization:
• The (ngSubmit) directive triggers the onSubmit() method when the form is
submitted.
• The form to add a new species is implemented using Angular Reactive Forms
(speciesForm), all are required fields. It contains the following fields:
Input Fields:
• Each input field and its label are placed inside a <tr>:
o Name Field
o Habitat Field
o Diet Field
o Population Field
o Submit Button
Form Layout:
• The form structure should mirror the layout of the Add Species Component.
Submit Button:
• The Submit button should be positioned in the last <tr> of the table and labeled
with 'Update Species'.
Functionality:
Submission:
• When the form is submitted and valid, a PUT request is sent to the backend to
update the species details. Upon successful update, the user is redirected to the
species list page.
The Species List Component dynamically displays species data in a table format, with
rows (<tr>) generated inside a <tbody>.
Table Structure
• The table headers (<th>) are organized in a single row (<tr>) inside <thead>.
• Name
• Habitat
• Diet
• Conservation Status
• Population
• Last Sighted
• Action
• The table rows are dynamically generated using Angular’s ngFor directive,
iterating over the species array:
o Action: The last column contains an "Edit" button, which uses [routerLink]
to navigate to the species editing page with the corresponding species ID.