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

Opt for Observable over Promise in your applications

I have implemented this function in one of my servlets: private setValues() { this.config.socket.on('config.weather', (values:any) => { console.log(values); } However, I would like to refactor it to something like this: private se ...

Enhance the <div> with interactive content through dynamic updates on click within the same element

I am currently developing an Editor-Menu for a website administration. When I open admin.php, the Editor-Menu should be loaded into the #ausgabe div using the code $('#ausgabe').load('./admin-ajax/ajax2.php'). This functionality is work ...

When is it appropriate to utilize props and CSS in customizing Material UI components?

As a beginner with Material UI, I'm curious about when to use props within the .jsx script and when to utilize CSS in a separate stylesheet to style MUI elements. Is it necessary to still incorporate CSS stylesheets for MUI elements or is it preferabl ...

Having trouble getting my parallax slideshow to work with jquery preventDefault

-UPDATE- After countless hours of online courses, tutorials, and programming, I finally completed my website! Check it out here: The site is almost where I want it to be, but there are a few remaining challenges: 1) AJAX: I'm struggling to get the ...

Validator returns undefined when expressing invalid data

Having an issue with validation, here is the code snippet: routes.js var express = require('express'); var router = express.Router(); var hello_controller = require('../api/controllers/helloController'); var { validationRules, validat ...

Encountering a problem with Selenium when dealing with tabular data displayed in a DIV format on a website, where each row is encapsulated within its own DIV element

While creating Selenium automation tests for a website with multiple rows contained within a main DIV element, each row represented by a separate DIV. For example, if there are 5 dynamically generated rows, the HTML code structure would look like this: < ...

Arrange floating elements in a three-column layout

Can anyone help me with a CSS solution to make boxes with different heights stack underneath each other neatly, similar to Tetris? Here's my code: CSS #page .equipeBox{ float:left; width:280px; padding:10px; margin:10px; backgro ...

What type of technology is typically utilized in creating functional platforms such as goDaddy, wix, and other web design websites?

I am currently working on a web development project that aims to allow users to edit webpages without needing any coding knowledge. Users with authorization will be able to modify not only the text but also various HTML tags on the page, similar to platfor ...

The parameter type 'Object' cannot be assigned to the parameter type 'JSON' in the HttpClient GET method

Hey there! Currently, I'm deep into developing an Angular 6 + Flask application and I've encountered a bit of a snag: Error TS2345: Argument of type 'Object' is not assignable to parameter of type 'JSON'. This issue arises w ...

How come certain rectangles vanish when one rectangle completely fills the space?

Currently, I am encountering an issue with CSS paint worklet and I am trying to determine if it's a browser bug or an error on my end. In the worklet, I am drawing multiple rectangles. Strangely, when one rectangle covers the entire area, the others s ...

Merge topics together in RxJS like zip

Is it possible to create an observable that combines two subjects in a unique way, different from the zip function? The goal is to combine two subjects so that when both have emitted values, the latest of their values is emitted. Then, after both emit at ...

What advantages does withStyles offer that surpasses makeStyles?

Is there a distinct purpose for each? At what point is it more suitable to utilize withStyles instead of makeStyles? ...

Transferring HTML variables to an Angular Component

I am currently trying to transfer the information inputted into a text-box field on my webpage to variables within the component file. These variables will then be utilized in the service file, which includes a function connected to the POST request I exec ...

What is the best way to update the mat-tab when the routeParameters are modified?

I need to reinitialize the mat-tab-group in order to make the first tab active when there is a change in the routeParams. ts file: public index = 0; ngOnInit() { this.subscription = this.route.params.subscribe((routeParams: Params) => { // some ...

Activate the dropdown menu when ul element is in focus

I am working on creating a dropdown navigation using pure CSS. I want the dropdown menu to appear when clicking on the ul. The issue I am facing is that simple ul:focus > ul does not seem to work, even though there is an anchor within it. However, the :hov ...

Aligning multiple spans vertically within a div of varying height (ui-select-multiple)

I am currently using AngularJS ui-select's Multiselect feature. If you want to see how my multiselect looks, check it out here: http://plnkr.co/edit/zJRUW8STsGlrJ38iVwhI?p=preview When arranging spans in multiple lines, achieving nice vertical align ...

Amazon has raised concerns about my use of an incorrect algorithm for signing requests

Need to include the string "AWS4" in my code implementation, which involves Angular and Python. In Python, I calculate the signature and then pass it to the frontend for sending the file to AWS. Here is a snippet of the signature and payload code: signa ...

What is the best approach to implement server-side rendering in Next.js while utilizing Apollo React hooks for fetching data from the backend?

I have a Next.js project that is utilizing Apollo GraphQL to retrieve data from the backend. My goal is to render the page using server-side rendering. However, I am encountering an obstacle as the React hooks provided by GraphQL Apollo prevent me from cal ...

Ensuring consistency in aligning float elements

I've been struggling to create a concept design for my internship project. I aim to have a page with six clickable elements (images). When one is clicked, the others should disappear and the active one moves to the top. I managed to achieve this using ...

Firefox experiencing issues with loading background images

The website URL: 4genderjustice.org While this layout functions properly in most browsers, notably Firefox seems to be causing issues. The question remains: why is it not functioning as expected in Firefox? The background images are configured like so: ...