How can we effectively showcase business entities on the user interface?

After receiving a list of persons from the backend, it is automatically transformed into TypeScript business object class (Person) objects using Angular/rxjs.

export class Person {
   Id: string;
   Name: string;
   Age: number;
}

The task at hand is to present these entities in a list with an extra column indicating whether records are selected or not - necessary for future processing.

The dilemma is - what would be the most appropriate approach to achieve this?

Should I create a PersonModel class that extends Person and includes an additional field for selection status?

export class PersonModel extends Person {
   Selected: boolean;
}

Alternatively, should I overlook the fact that the back-end does not involve the Selected property and simply add it to the existing Person class?

export class Person {
   Id: string;
   Name: string;
   Age: number;
   Selected: boolean;
}

Are there alternative methods that are more suitable for addressing this scenario?

Answer №1

One way to approach object-oriented programming is by utilizing interfaces that extend other interfaces rather than creating classes.

export interface Human {
   Id: string;
   Name: string;
   Age: number;
}

export interface HumanAttributes extends Human {
   Selected: boolean;
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Intercepting Nested Requests in a Nest.js Application

Can you explain how to incorporate a nested interceptor in Nest.js? I currently have two interceptors: UsersInterceptor and PostsInterceptor UsersInterceptor: @Injectable() export class UsersInterceptor<T> implements NestInterceptor<T, Response& ...

Challenges with TypeScript's typeof operator and instantiation of classess

Discussing the scenario of a map setup: const map = { a: ClassA, b: ClassB, c: ClassC, } The purpose of this map is to link different classes together. There exists a function that returns an instance of a class based on a key in the map ...

Guide on implementing Observables in Angular 2+ to update a single entry in a table in real-time

I'm facing a challenge with my Angular4 and Node.js application. I have a table that displays data with 7 columns using *ngFor. The issue arises when I need to update the last column dynamically and in real-time. Specifically, I want to show a green c ...

Using Typescript to reduce an array of objects results in concatenation

In my quest to calculate the sum of integers from an array of objects stored in a redux slice, I have encountered a challenge. Here is the code snippet in question: export type Expense = { id: string; title: string; amount: number; date: st ...

The primary HTML file in Angular is unable to access the styles.scss file located in the src/styles directory

Just starting out with Angular. To incorporate the 7-1 scss pattern into my project, I established a styles folder within the src directory named "src/styles", and connected the components to the src/styles/style.scss file successfully. However, I'm ...

Learn the steps to refresh a component in Angular 5

src/shared.service.ts public _testData:any;   set testData(value:any) {     this._testData = value   }   get testData():any {     return this._testData;   } src/header.component.ts private postValues( ...

The date displayed in the table is incorrectly showing 04 instead of 03 when using the pipe

{{element.createdAt | date: 'MM/dd/yyyy h:mm'}} why are the dates in the database all showing as 23 but some values are displaying as 24? Please confirm. The first two values created in the db show a createdAt time of 3, but the table is showing ...

The asynchronous function is not returning a value and is currently at a standstill

Looking to retrieve the user data of a logged in user from Google Firebase, I have implemented two methods for this purpose. One method fetches the authState, while the other collects more detailed information under UserInfo. These methods are encapsulate ...

What is the best method to integrate my custom Angular Single Page App instead of a webpage using Greasemonkey?

How can I use Greasemonkey to replace the HTML code of a website with my own Angular Single Page App? Motivation: I have come across an old website that is in need of a redesign, but the owner seems uninterested. I want to create an Angular SPA that will ...

Exploring the capabilities of utilizing Typescript decorators alongside the Parse SDK JS

In my Typescript project, I am utilizing the Parse SDK JS and have crafted a model class named Person that extends Parse.Object. This class is designed to store data on the server: import * as Parse from 'parse/node' class Person extends Parse. ...

Angular 5: encoding API requests

Is there a way to synchronize API calls in Angular 5? In my project, I have a form that triggers an API call whenever the user inputs something. However, I need to ensure that if the user updates the input while a previous API request is still pending, th ...

Instantiate an object of the ng.IQService type without using injection

Is it possible to define a local variable in the controller of type ng.IQService ( private _q: ng.IQService;) without requiring injection? My technology stack includes typescript and angular. The reason for this requirement is due to existing legacy code ...

Having trouble finding the module for declaration in ASP.NET Core with Angular?

Encountering issues while attempting to create new Angular components with the command ng g component login-form Error finding module for declaration. No module files located. It seems that the angular CLI is throwing errors due to the differing file ...

Uploading images to an S3 bucket using Angular4 and saving the response.Location in a global variable for easy access in other functions or methods

Hello, I am currently working on uploading an image to an Amazon S3 server using Angular 4. My goal is to retrieve the response.Location, which is returned from S3 as a URL, and save it to a global variable for easy access. However, I am facing some challe ...

I am looking to incorporate two interceptors within the Angular application - one dedicated to user authentication and another specifically for admin authentication

I am trying to differentiate between user requests and admin requests in my app. The goal is to have user requests pass through the UserAuthInterceptor, while admin requests go through the AdminAuthInterceptor. How can I separate these interceptors within ...

Tips for handling a function only after the model window has returned a promise in Angular 2

When a button is clicked, three functions are called in sequence within a promise. The first function is responsible for blocking a model window and returning a promise which then resolves the next function. The HTML code snippet is as follows: ...

"Troubleshooting: Issue with component not refreshing in app.component.html

I've been working on setting up the layout of my app in the app.component.html file. One thing I did was create a menu component with its own selector. Here is how my code currently looks: <app-menu></app-menu> <router-outlet>< ...

Troubleshooting issues encountered while sending HttpClient Get Requests from Angular Front-End to Node.js Back-End

I am encountering an issue where I keep getting the error message "Cannot GET /" on my local host URL when attempting to send a HttpClient get request from my Angular front-end to my Node.js back-end endpoint. Despite the fact that my back-end endpoint suc ...

Error occurred: Unable to locate module: Error: Unable to resolve './templates'

Currently, I am working on a TypeScript file named index.ts which includes some JavaScript code. The main functionality involves importing Bootstrap CSS and templates. import '../node_modules/bootstrap/dist/css/bootstrap.min.css'; import ' ...

The child module is unable to locate the route URL for the parent module

I'm new to Angular and I'm working on organizing my code into modules. So far, I have an admin module that responds to the /admin request, but now I want to add a child module called Portfolio Module. Everything is working fine, except for the f ...