Construct a table utilizing Angular's ngFor directive that includes two rows, with the first row containing a single value from an array of objects and the second row displaying the remaining values

In my new project, I am utilizing angular. I am curious about how to optimize this code snippet with a more elegant approach using just one *ngFor directive.

<table>
<tr>
<th *ngFor="let distribution of monthDistribution ">{{distribution.month}}</th>
</tr >
<tr>
<th *ngFor="let distribution of monthDistribution ">{{distribution.hc}}</th>  
</tr>
</table>

The array monthDistribution is structured as follows :

[{month : "1", hc :"15.2"},...,{month : "12", hc :"19.2"}]

Essentially, I aim to have only one table header displaying all months and one table row showcasing the corresponding hc values. Even though altering the data format by using the month value as the key for hc is an option, I fail to see how it would address my issue.

Thank you very much.

Answer №1

<div>
  <ul *ngFor="let item of items">
    <li *ngIf="item.condition === 'ready'">{{ item.name }}</li>
  </ul>
</div>

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

Issue with Angular Elements: Zone.js has identified that ZoneAwarePromise has been detected

I've been experimenting with Angular Elements by creating two custom elements: a simple button and a basic input field. You can find them at these links: and Each element includes its own polyfills, main, runtime scripts, and styles bundled together ...

Tips for creating type-safe assertion functions in TypeScript

In TypeScript 3.7, a new feature allows the writing of "assertion functions." One example is shown below: export type TOfferAttrName = keyof typeof offerAttrMap; export const assertIsOfferAttrName = (name: string): asserts name is TOfferAttrName => { ...

Centralize all form statuses in a single component, conveniently organized into separate tabs

I am working on a component that consists of 2 tabs, each containing a form: tab1.component.ts : ngOnInit() { this.params = getParameters(); } getParameters() { return { text : 'sample' form: { status: this.f ...

Is there a way to simultaneously filter by two attributes using mat-select-filter in Angular?

I have integrated the mat-select-filter library in my Angular project, but I am facing an issue with the displayMember filter. Currently, it only filters by code, but I would like it to also filter by name simultaneously. Is there a way to achieve this u ...

Angular 12's 'ng serve' feature seems to be taking its time building apps, almost mimicking the slower pace of production

After upgrading my app from Angular 11.2.7 to Angular 12, I've encountered a frustrating issue. While everything runs smoothly, the rebuild times during development using 'ng serve' have slowed significantly. My M1 iMac, running node 16.1.0 ...

Replacing a push operation in JavaScript with a splice operation

Upon entering a screen, 5 promises are automatically loaded using promise.all. The issue is that they are executed in a random order, and within each function, I use a push to store the information. The problem arises when I need to change the push to a s ...

Replace Angular Material Component with a new custom component in Angular

In order to customize the Angular Material select component (https://material.angular.io/components/select/overview) to have an input field transformed into an icon button, I attempted to override its styling. While this approach worked well for me, I came ...

What is the best way to extract a variable value from the subscribe method and make it available for use in an Angular 10 service method's return statement using TypeScript?

getProductbyFilter(filter: filterDataModel): Observable<any> { this.stringtoArrayService.convertStringtoArray(some string input).subscribe(productUserResponse => { if (productUserResponse) { this.userProfileProduct = productUserResponse; ...

Discovering the ASP.NET Core HTTP response header in an Angular application using an HTTP interceptor

I attempted to create a straightforward app version check system by sending the current server version to the client in the HTTP header. If there's a newer version available, it should trigger a notification for the user to reload the application. Ini ...

Proper utilization of react-hook-form in conjunction with TypeScript and material-ui to display error messages efficiently

Currently, I am using a combination of react-hook-form with typescript and material-ui. My goal is to pass the error message as a helperText to the TextField. I attempted to achieve this by utilizing helperText={errors.email?.message} however, TypeScript ...

I have been attempting to incorporate icons from fluent ui northstar into the fluent ui dropdown component, but unfortunately, there is a lack of adequate documentation

I attempted to use renderItem to include a divider and Icon in a Fluent UI dropdown menu, but the icons are not visible. Even the default value does not display the icons, and the dropdown menu does not appear after clicking. import * as React from " ...

Tips on expanding typings in TypeScript?

In my software library, there exists a map function with the following definitions: function map<T, U>(f: (x: T) => U, a: Array<T>): Array<U> function map<T, U>(f: (x: T) => U, a: Functor<T>): Functor<U> Furtherm ...

Customizing the text color of words that originated from a dropdown selection within an Angular textarea editor

My Process: Within my interface, I utilize both a dropdown menu and a textarea field. I input text into the textarea and select certain words from the dropdown menu to add to the textarea. I have successfully completed this task. The Issue at Hand: Now, ...

The tsconfig within the module directory fails to supersede the extended tsconfig properties present in the parent directory

Within the directory store/aisle/fruits, there is a tsconfig.json file: { "compileOnSave": true, "compilerOptions": { . . "target": "es6", "noEmitOnError" : true, "noEmitHelpers ...

Error message stating 'Module not found' is displaying in the browser console

As a beginner with Angular CLI, I recently executed the following commands at the root of my Angular project. issue-management\src\webui>ng generate module pages\dashboard issue-management\src\webui>ng generate component pag ...

Identifying the state type within the scope of TypeScript

For my project involving BMI calculation, I want to store the results in an array within a state and keep them locally. export type BmiContextState = { weight: number | undefined; height:number | undefined; open:boolean|undefined; alert:boo ...

Steer clear of making changes to a JavaScript array

Here is my code snippet: let traces = { ref: null, min: null, max: null, avg: null }; let learning = { "Application": "b3", "t": [ { "d": 2, "BinaryType": "Current" }, { "d": 3, ...

Personalized Functions Using Material Design Expansion Panel Header Icon

Here's a unique material design accordion with an icon added to the panel header. I want to invoke my function 'myFun()' on click event, but currently, the expansion panel is toggling each time it's clicked (which is not the desired beh ...

Using TypeScript to pass the text field ID to a function for clearing the text field with a button

I am looking for a way to improve the functionality of my web page featuring several buttons that will clear different text boxes on the same line. Currently, I am using separate functions for each button, but my goal is to streamline this process by utili ...

Utilizing the filter function with serverSide rowModelType in ag-grid

Successfully integrated ag-grid with server side rowModelType implementation. Placed an input textbox above the grid for filtering purposes. When a user types in the search query "abc", it triggers a call to the server with "searchString=abc" included in ...