Exploring intricate JSON data in Angular 4 applications

Below is the json structure I have:

[
   {
      "section":{
         "secName":"Module 1",
         "pages":[
            {
               "pageName":"Page 1",
               "pageType":"brightcove",
               "pageData":[
                  {
                     "Title":"Title 1",
                     "Question":"Question 1",
                     "Answer":"Answer 1"
                  }
               ]
            },
            {
               "pageName":"Page 2",
               "pageType":"expose",
               "pageData":[
                  {
                     "Title":"Title 1_2",
                     "Question":"Question 1_2",
                     "Answer":"Answer 1_2"
                  }
               ]
            },
            {
               "pageName":"Page 3",
               "pageType":"text-image",
               "pageData":[
                  {
                     "Title":"Title 1_3",
                     "Question":"Question 1_3",
                     "Answer":"Answer 1_3"
                  }
               ]
            }
         ]
      }
   },
   {
      "section":{
         "secName":"Module 2",
         "pages":[
            {
               "pageName":"Page 1 222",
               "pageType":"brightcove",
               "pageData":[
                  {
                     "Title":"Title 2 1",
                     "Question":"Question 2 1",
                     "Answer":"Answer 2 1"
                  }
               ]
            }
         ]
      }
   },
   {
      "section":{
         "secName":"Module 3",
         "pages":[
            {
               "pageName":"Page 1 3",
               "pageType":"brightcove",
               "pageData":[
                  {
                     "Title":"Title 3 1",
                     "Question":"Question 3 1",
                     "Answer":"Answer 3 1"
                  }
               ]
            },
            {
               "pageName":"Page 3 44444",
               "pageType":"text-image",
               "pageData":[
                  {
                     "Title":"Title 1_34",
                     "Question":"Question 1_34",
                     "Answer":"Answer 1_34"
                  }
               ]
            }
         ]
      }
   }
]

I successfully retrieved and displayed the section names (secName) using the code snippet below.

<ng-container *ngFor="let modName of inputObjResponse; let i = index">              
     <div class="modname" (click)="moduleSelected($event, i)">               
           <h3>{{modName.section.secName}}</h3>
     </div>
 </ng-container>

Now I'm seeking assistance to display only the pageName values from "Module 1" (Page 1, Page 2, Page 3), but I haven't found a solution yet. Any suggestions on achieving this task would be greatly appreciated. Additionally, feedback on whether the current structure is correct or needs modifications is welcomed as well.

Answer №1

Simply add another ngFor loop

<ng-container *ngFor="let mod of inputObjResponse; let i = index">           
    <ul>
        <li *ngFor="let page of mod.section.pages">{{page.pageName}}</li>
    </ul>
    <div class="modname">               
        <h3>{{mod.section.secName}}</h3>
    </div>
</ng-container>

Check out the StackBlitz demo!

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

Jasmine encountered an error while trying to compare the same string: 'Expected the values to match.'

I'm encountering an error message, despite verifying that the strings are identical: Expected { $$state : { status : 1, value : { customerNumber : 'customerNumber', name : 'name', userId : 'buId', customerType : 'ty ...

Error encountered in Angular 17 SSR: Importing module "@angular/ssr" does not have the exported member "REQUEST"

I'm having trouble getting cookies on Angular 17 with SSR. In the past, I was able to use the REQUEST pulled from @nguniversal/express-engine/tokens, but now with @angular/ssr, I can't find where to pull REQUEST from. import { REQUEST } from &apo ...

Utilizing lodash and Angular 8: Identifying an valid array index then verifying with an if statement

In my current project, I am developing an e-commerce angular application that includes a basket with two types of products: restaurant + show combos and gift cards. When a client reserves a restaurant, they must also reserve a show; conversely, the client ...

Tips for integrating JavaScript libraries with TypeScript

I'm looking to add the 'react-keydown' module to my project, but I'm having trouble finding typings for it. Can someone guide me on how to integrate this module into my TypeScript project? ...

What is the process for including an optional ngModelGroup in Angular forms?

I'm encountering an issue with incorporating the optional ngModelGroup in angular forms. Although I am familiar with how to use ngModelGroup in angular forms, I am struggling to figure out a way to make it optional. I have attempted to pass false, nu ...

Leveraging Angular 8's HttpClient to retrieve and display a complex JSON object in an HTML table

I am currently working with Angular 8, where I need to query an endpoint to fetch an object. Upon calling the endpoint using Advanced REST Client, I receive the following JSON response: GET: http://localhost:8090/curso_conductor/ Response: { "dato": [ ...

What is the best way to showcase the Observable information I receive from calling my api with Angular?

Just beginning my journey with Angular, I am on a quest to create a simple app that showcases a catalog of products. In my TypeScript file, I have a getProducts() function that calls an API and returns an observable list of products consisting of attribute ...

Make sure to verify if the mode in Angular is either visible-print or hidden-print

Here is a snippet of code <div class="row"> <div class="col-sm-12 visible-print"> Content (display in full width when printed) </div> <div class="col-sm-6 hidden-print"> Content (same as above but only half width when ...

Mocking Firestore v9 getDocs() in Jest: A Comprehensive Guide

After upgrading our webapp from Firebase v8 to v9, we encountered various issues due to the new syntax. As I am still relatively new to Jest and Firebase/Firestore, not everything is completely clear to me yet ... I am attempting to mock getDocs from fire ...

The HTTP GET request was successful, however, there is no data being displayed on the screen

I am currently facing an issue with fetching data from a web server. The data is retrieved successfully as I can see the object in the console log, but it does not render in the component template. export class CountrydetailsComponent implements OnInit { ...

Filtering JSON by a specific value in Ionic 2 app

Recently, I've started working with Ionic 2 and Angular. I'm trying to filter a JSON data to display only specific values, like getting users by gender. Below is the code snippet I tried: home.html <ion-list> <ion-item *ngFor="let ...

Can we guarantee that the key and its corresponding value are both identical strings in Typescript?

Is it possible to enforce the key of a Record to be the same as the inner name value in a large dataset? interface Person<T> { name: T title: string description: string } type People = Record<string, Person<string>> // example dat ...

Transferring the web application context to an Angular2 service

In my project, I am attempting to pass a variable named _contextPath from a Javascript evaluated variable in a JSP file located in the folder structure shown below. The goal is to make this _contextPath variable available in a Typescript Service called job ...

Assign a value to a variable using a function in Typescript

Is there a way in typescript to explicitly indicate that a function is responsible for assigning value to a variable? UPDATED CODE Here, the code has been simplified. While getText() ensures that it will never be undefined, this may not hold true in subs ...

using the ts-migrate-mongoose package for migrating MongoDB

I'm currently working on a NestJS application and using ts-migrate-mongoose for database migration. The issue I'm facing is related to importing a user schema from outside of the migration folder (which is located in the root folder by default). ...

Issue: potentially harmful data utilized in a URL resource setting

Looking for some assistance - I'm attempting to embed a YouTube video onto my HTML page, but encountered an error message that reads: "Error: unsafe value used in a resource URL context." Upon reviewing my code, everything appears to be correct, and ...

Using class-validator in Node.js to validate arrays of objects

My goal is to verify the Alcohol ID and Alcohol Name for emptiness. Below is the format I am working with: { "barId": "string", "barName": "string", "drinksItems": [ { "alcoholId": "string", "alcoholName": "string", "mixerLis ...

Typescript encounters issues when assigning declaration as TRUE

Currently, I'm working on a project in Angular 2 and attempting to create TypeScript definitions for it so that it can be exported as a library. I have various services set up that make HTTP requests to components, all structured similarly to the cod ...

Issue with Type-Error when accessing theme using StyledComponents and TypeScript in Material-UI(React)

I attempted to access the theme within one of my styled components like this: const ToolbarPlaceholder = styled('div')((theme: any) => ({ minHeight: theme.mixins.toolbar.minHeight, })); This information was found in the documentation: htt ...

Unable to Anticipate User Input in Angular Using Scanner or Keyboard

Currently grappling with Angular 6 and facing an issue. I have a text box and a submit button, with a requirement for functionality to allow input through either manual keyboard typing or a Barcode scanner. The desired behavior is for the submit button to ...