Adjust the alignment of divs in Angular

In developing a dashboard, I have successfully displayed key value pairs in a component by retrieving them from an environment.ts file. Now, I am looking to rearrange the positioning of the individual testcard components to align with a specific layout shown in the mockup.

https://i.sstatic.net/eURtc.png

As a newcomer to Angular, I am uncertain if I can achieve this desired layout by utilizing ng container and adjusting the divs' positions accordingly.

Snippet from environment.ts:

col: 'col-6',
                            title: 'test',
                            info: 'testinfo',
                            content : [
                                {
                                    title: 'testvaluediv1',
                                    key: 'testvalue',
                                    pipe: {
                                        name: 'number',
                                        value: '1.0-0'
                                    },
                                    postFix: {
                                        text: 'test',
                                    },
                                    color: 'info',
                                    size: 'large'
                                },
                                   {
                                    title: 'testvaluediv2',
                                    key: 'testvalue',
                                    pipe: {
                                        name: 'number',
                                        value: '1.0-0'
                                    },
                                    postFix: {
                                        text: 'test',
                                    },
                                    color: 'info',
                                    size: 'large'
                                },
                                   *// till test5
                                }
                            ]
                        }

HTML code where the component is used:

  <ng-container *ngFor="let config of config?.content" >
  
                <test-card *ngIf="!config.id" 
                    [config]="config"
                    [entity]="boxes[config?.key]"
                    
                ></test-card>

            </ng-container>

Template for the test-card component:

<div>
<span *ngIf="config?.preFix?.icon" [class]="'pr-2 icon '+ config?.preFix?.icon"></span>
<span>{{config?.preFix?.text}} {{entity?.value | cut}} {{config?.postFix?.text}}</span>
<span *ngIf="config?.postFix?.icon" [class]="'pl-2 icon '+ config?.postFix?.icon"></span>
</div>
<div>
<span>{{config?.title}}</span>
</div>

Current output received:

https://i.sstatic.net/YNcV9.png

Answer №1

Utilizing only CSS, this task can be accomplished. Referencing this solution.

Take a look at the following:

grid-container {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(4, 100px);
  grid-gap: 10px;
}

grid_item:nth-of-type(3n+1) {
  grid-column:span 2;
  grid-row:span 2;
}

/* additional decorative styles */
grid_item {
  background-color: aqua;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 1.5em;
}
<grid-container>
  <grid_item>A</grid_item>
  <grid_item>B</grid_item>
  <grid_item>C</grid_item>
  <grid_item>D</grid_item>
  <grid_item>E</grid_item>
  <grid_item>F</grid_item>
</grid-container>

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

When using routerLink, it automatically converts the URL to a

I am currently working on an Angular project where I need to link to bookmarks on other pages. In my HTML, I have links structured like this: <a href="#products" routerLink="overview">products</a> However, during compilation and execution of ...

Encountered a problem during the installation of Angular 4

Recently delving into angular, my journey began with the installation of node js on my machine. Following this link, I attempted to install angular, only to be met with the following error: gyp verb check python, inspecting if Python executable "python" i ...

Unable to utilize the concatMap() method in conjunction with the angular2 Http feature

Looking to chain multiple http requests, the number of requests can vary and they are not dependent on the previous request's result. The goal is to only keep the returned object from the last request. Received two suggestions on this forum thread. T ...

If an error occurs during ng lifecycle hooks, router.navigate will not function correctly

I've developed an ErrorHandler specifically for logging exceptions and then redirecting the user to a generic error page. However, a recurring problem arises when the exception occurs within a lifecycle hook or constructor method. Take for example the ...

Utilize the power of Wikitude within an Angular 2 application

I am currently working on integrating Wikitude Architect View in Angular 2 by referring to the code at this link. My goal is to implement this code in an Angular 2 compatible way. import * as app from 'application'; import * as platform from & ...

Guide on how to bundle a TypeScript project into a single JavaScript file for smooth browser integration

I am currently working on a small project that requires me to write a JavaScript SDK. My initial plan was to create a TypeScript project and compile it into a single JavaScript file, allowing users of my SDK to easily inject that file into their web pages. ...

Fixing the Unspecified addEventListener ErrorLearn how to resolve this error

Having recently started working with Angular, I encountered an issue with my addEventListener method not functioning as intended. My goal is to create a delete button that removes a specific array from my input. This array is nested within a mat-card tag a ...

The functionality of the Request interface appears to be malfunctioning

Hey there, I'm currently working on building an API using Express and TypeScript. My goal is to extend the Request object to include a user property. I've done some research on Google and found several posts on StackOverflow that explain how to d ...

RouterModule is a crucial external component that is essential for integrating

If I have a very simple component that is part of an Angular component library, it might look like this: mycomponent.module.html <div> <a routerLink="/"> </div> mycomponent.component.ts import { Component, OnInit, Input } from &a ...

Observable map encounters an error when attempting to retrieve essential data from the backend server

Here is my approach: getDropdownData(id: number | 195731): Observable<ClinicTrialSettingProp> { return this.http .get<ClinicTrialSettingProp>(this.commonPatientURL + id + '/clinic-trials') .pipe(map(response => res ...

What is the best way to securely store JWT refresh tokens on both the front-end and back-end?

Storing the refresh token on the client side in "Local Storage" poses a significant security risk. If a hacker gains access to this token, they could potentially have everlasting access to the user's account by continually refreshing both access and r ...

Will a JavaScript source map file continue to function properly even after the source code file has been minified?

My experience I specialize in utilizing TypeScript and Visual Studio to transform highly organized code into functional JavaScript. My skills involve configuring the project and Visual Studio to perform various tasks: Merging multiple compiled JavaScrip ...

Troubleshooting: Empty Rows displayed in PrimeNG Table

Experimenting with Angular 8 and the primeNG package, I'm facing an issue where I cannot retrieve values. Despite using the {{staff[col.field]}} syntax, I only get empty rows of data. However, when I utilize the interface definition like {{staff.Emplo ...

A TypeScript example showcasing a nested for-of loop within several other for loops

Is it possible to generate values from an Array of objects in the following way? const arr = [ { type: "color", values: [ { name: "Color", option: "Black", }, { name: "C ...

Eliminate elements from an array using a specific key for filtering

My Array is called MainArray MainArray=[{ {First Name: "First Name"}, {Last Name: "Contact"}, {Last Name: "Contact"} ] I am trying to trim the key-value pair from this array like this: if (key == 'First Name') { del ...

Extracting Object Properties from Arrays in TypeScript

Code Snippet: interface Human { name: string; age: number; } interface Pet { name: string; type: string; } If I have an array of Human, how can I get an array of Pet's type. For instance: Is there a built-in way to achieve this in typescr ...

Issue with package: Unable to locate the module specified as './artifacts/index.win32-ia32-msvc.node'

I am encountering an issue while using Parcel for the first time. When I execute npx parcel .\app\index.html, I receive the following error: Error: Module not found './artifacts/index.win32-ia32-msvc.node' Require stack: - C:\Users ...

Customizing the Android Back Button behavior in NativeScript for a single specific page

I am currently using NativeScript version 5.2.4 along with TypeScript. My goal is to disable the back button functionality in one specific page only, but I'm facing an issue where it also disables the back button behavior for child pages. Below is the ...

What is the proper way to define the Typescript type of the return value from the dispatch function in a Redux application?

fetchSomething is defined as follows: export const fetchSomething = createAsyncThunk( 'something', async () => { return Promise.resolve({name: 'jack'}) } ) This is the code within a React component: const dispatch = useApp ...

How can I adjust the font size property for Material UI Icons through typing?

I put together the code snippet below, and I'm trying to define a specific type for the custom iconFontSize prop. Can someone guide me on how to achieve this? import { SvgIconComponent } from '@mui/icons-material' import { Typography, Typogr ...