Having difficulty displaying data in the proper format with two-way binding

In the realm of my webpage, I have a plethora of headings, paragraphs, images, and other data at my disposal. From the backend, a dataset is provided to me that includes an array with various properties housing the desired information. The challenge lies in presenting this data on the page based on these properties. Here is a snippet of the data retrieved from the backend:

{
  "result": {
    "slogan": "Majeed",
    "bannerImage": "data:image/png;base64,...",
    "schoolName": "JPSC",
    "schoolTenancyName": "JPSC",
    "logo": null,
    "city": "Harbel",
    "county": "Kakata",
    "district": "Kakata",
    "addressline": "319-Hadi Street, Alhamd COlony, Allama Iqbal Town",
    "profilePageContents": [{
        "id": "355156f4-3499-4883-846d-e41bed8a2765",
        "heading": "Yamaha",
        "paragraph": "Hello Guys this is ahsan nissar and this is my school profile page and you can",
        "image": "data:image/png;base64,...",
        "alignment": "Left"
      },
      {
        "id": "d06ce9a5-94a9-4433-adda-ed7efe93f5b2",
        "heading": "Hello friends",
        "paragraph": "I am Ahsan and this is my school. No one can enter here without permission.",
        "image": "data:image/png;base64,...",
        "alignment": "Left"
      }
    ]
  }

My task now is to display the profilePageContents, considering the specified property that triggers how the pictures and paragraphs are shown. Upon inspecting the preview, it is evident that all paragraphs are displayed indiscriminately, which is not the intended outcome.

To tackle this issue effectively, I have included relevant TypeScript code below:

... Detailed TypeScript code omitted for brevity ...

Upon reviewing the HTML implementation, it seems that there might be room for improvement in how the paragraphs are rendered based on their alignment. If finding a solution involves leveraging Angular class binding or making adjustments using DOM manipulation, any guidance on this matter would be greatly appreciated. Thank you!

Answer №1

Your code can be improved by eliminating the unnecessary part below:

this.data = this.publicData.profilePageContents.map(item => item.paragraph);
this.align = this.publicData.profilePageContents.map(item => item.alignment);
for (let i....

Here are some solutions to consider: 1. Utilize the even or odd properties of the *ngFor loop in order to determine whether to apply the classes paraLeft or paraRight. Check out more information at https://angular.io/api/common/NgForOf 2. Implement flexbox for alignment control.

Visit this link for a sample solution: https://stackblitz.com/edit/so-list-example

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

Google Chrome does not display Set-Cookie header on page loads

Issue Having trouble with the Set-Cookie header not showing up in the response headers when making a request to a Spring Boot server's Post endpoint from an Angular app in Chrome's dev console. Summary of Findings Set-Cookie does appear in res ...

What causes @typescript-eslint to retain old types/files in its cache and prevent successful compilation?

When I kick off my Typescript application using tsc -b -w, I always encounter an issue with @typescript-eslint not reacting to file changes accurately. It flags invalid types/syntax errors where there are none. Restarting the process sometimes doesn't ...

Is there a faster alternative to using jQuery's indexOf method?

Looking to create a search box for a large set of options (around 2000 options) The indexOf method is very slow...any alternative solutions? Jquery Code : $('#textfortitlesearch').on('keyup', function() { var query = this.value ...

Issue with default behavior of infinite scroll in Angular 4

I'm currently working on incorporating infinite scroll into my Angular 4 application. I've carefully followed all the guidelines provided on https://www.npmjs.com/package/ngx-infinite-scroll According to the documentation: By default, the dir ...

I want to display a background color using this ng-template

enter image description hereMy code includes an ng-template that uses ngFor to generate internal HTML tags without the ability to add CSS properties. <ng-template *ngFor="let c of colors" contextMenuItem let-item (execute)="change_task_color($event.ite ...

The server is taking too long to respond, resulting in a 504 Timeout error

I currently have an Angular frontend paired with a .NET CORE backend. The issue I am experiencing is related to a specific request that is resource-intensive and takes a significant amount of time to complete. Whenever I check the browser console, I receiv ...

Developing a TypeScript frontend library

I am currently in the process of creating a frontend library consisting of React components and CSS/SCSS. Specifically, I am looking for: To build a single CommonJS .js file and .css file. To exclude external libraries (e.g. React) from the .js output. ...

Focused on individual characters in a string to implement diverse CSS styles

Is there a way I can apply different CSS classes to specific indexes within a string? For example, consider this string: "Tip. \n Please search using a third character. \n Or use a wildcard." I know how to target the first line with CSS using : ...

What's the best way to ensure my website's footer spans the entire width of the webpage?

<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Elena Brown | Graphic Designer</title> <link rel="stylesheet" href="CSS/normalize.css"> <link href=' ...

Having difficulty updating the value of a FieldArray with setFieldValue in Formik

Thank you for taking the time to read this. I am currently working on creating a form using Formik that involves nesting a FieldArray within another FieldArray. Oddly enough, setFieldValue seems to be functioning correctly as I can log the correct values ...

Converting JavaScript CanvasRenderingContext2D states array into a serialized format

Looking for a way to serialize a canvas' state in order to save it to a database for later restoration. Want to store the data as an object rather than a bitmap file. I've tried using .save() and .restore() on the context object, but they only m ...

Issues with Observable<boolean> functionality

Can anyone lend a hand? I'm facing a challenge with this function that is crucial for the application. Typescript File get $approved(): Observable<boolean> { return this.$entries.map(entries => { if (entries.length > 0) { ret ...

The Validation Library known as 'Yup' encounters compilation issues with TypeScript

After deciding to utilize the Yup library for form validation in my project, I encountered a persistent and confusing library error each time I tried to install it. This issue has been plaguing me despite numerous attempts to troubleshoot. Any suggestions ...

Stopping horizontal scrolling in Material-UI Autocomplete/Popper: A troubleshooting guide

I am currently working on incorporating the Material-UI Autocomplete component, and my goal is to have each option label show an icon along with some text. The challenge I'm facing is that I only want the popper element to be the width of the text inp ...

Is there a specific type that is narrower in scope when based on a string parameter?

tgmlDoc.createElement(tagName) typically returns objects of type any. I am looking to refine the return type in the function below in order to simplify the rest of my code. Is there a way to accomplish this? My attempt is shown below, but unfortunately, ...

Authentication Redirect Failure when using Passport to an absolute URL

I am looking to redirect the user to a different URL with the code/token received after logging into Facebook using Passport in Express.js. app.get('/auth/facebook/callback', function (req, res, next) { var authenticator = passport.authentic ...

Vue 3 has officially deprecated the use of ::v-deep as a combinator. Going forward, please utilize ::v-deep(<inner-selector>) instead

Recently, an error message has been popping up in Vue 3 regarding the use of ::v-deep. The warning states that using ::v-deep as a combinator is deprecated. Instead, it recommends using ::v-deep(<inner-selector>) Here is an example of the CSS ...

The error message "Property 'value' is not present on type 'EventTarget & HTMLSelectElement'" indicates that the 'value' property is not recognized on the Event

Here is the code snippet that I am working with: interface IHandleSelection { (value: string): any | void; } interface IPipeChangeEventValueToFunction { (handler: IHandleSelection): (event: React.ChangeEvent<HTMLSelectElement>) => void; ...

Organizing data with JavaScript: Transforming a flat array into nested JSON structures

In my front-end TypeScript file, there is a list called poMonths: 0: {id: 1, companyName: "company14", companyId: 14, flActive: true, purchaseMonth: "2019-12-15T00:00:00", purchaseMonthString: "Dec-2019" , year: 2019, month: "December"} 1: {id: 2, company ...

What is the best way to give an element or container a variable width rather than a fixed width?

I have a query regarding positioning and variable width. I've applied the following CSS: *{ border: 1px dotted blue; /*indicator for where every element are positioned or spaced on the page*/ } By adding this to all elements, I can visualize their p ...