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

Is it possible to refresh the webpage in Angular when the tab is clicked?

Can someone help me find a solution to reload an Angular app's page when the user selects the browser tab? I've been exploring using window.location.reload() for this purpose, but I need guidance on triggering it specifically when the tab is sel ...

What is the best way to recycle a single modal in Ionic?

Apologies for the vague title, but I'm facing an issue with creating a single modal to display data from multiple clickable elements, rather than having separate modals for each element. For example, when I click on item 1, its data should be shown in ...

Guidance on specifying a type based on an enum in Javascript

I have a list of animals in an enum that I want to use to declare specific types. For instance: enum Animals { CAT = 'cat', DOG = 'dog', } Based on this Animal enum, I wish to declare a type structure like so: type AnimalType = { ...

simulate the behavior of a promise function within a class

I'm facing an issue with this class structure: @Injectable() class ServiceOne { method1(): Promise<any>{ return new Promise((resolve,reject)=>{ // performing some operations let value = 1; resolve({'value':1}); }); } ...

Implement Angular in a non-conventional Angular-based venture

Is there a way to incorporate Angular into a project that is built on a different framework? Specifically, I have a .NET MVC project that uses Razor for the markup. I want to make some ajax calls and update parts of the UI without using JQuery. Instead, I ...

Setting the sidebar width for Nebular with two sidebars in the layout: A step-by-step guide

Having two sidebars (identified as left and right) in my page layout, I initially set both sidebars to a width of 400px using the custom theme method with sidebar-width: 400px. However, I now need to change the width of the right sidebar to 700px. Is the ...

Creating a flexible parent tag for grouping child elements using Angular 2

My Objective I am determined to develop an Angular 2 button component that can dynamically render as either an <a /> tag or an <input /> tag based on the value of a property called type. Furthermore, this button component should be able to acc ...

The typescript MenuProvider for react-native-popup-menu offers a range of IntrinsicAttributes

Looking to implement drop-down options within a Flatlist component, I've utilized the React Native Popup Menu and declared MenuProvider as the entry point in App.tsx. Encountering the following error: Error: Type '{ children: Element[]; }' ...

The element did not match the Angular Routing selector "app-home"

How can I prevent my initial component from being loaded twice in Angular? I am trying to implement a default/empty component to avoid the AppComponent being loaded within itself. The empty component would serve as the starting point for loading other comp ...

React Native Component Error: Cannot read property '_this' of undefined

I am currently developing a face recognition application using React Native 0.63. I'm running my project using react-native run-android. However, I encountered an issue with Component Exception where it shows 'undefined is not an object (evaluati ...

The metadata for [object Module] does not contain any ngModule information

I recently made changes to my routes by switching them from lazy loaded using a string reference to lazy loading through a call to import. However, I am facing an issue where every time I try to navigate to one of the pages, I encounter the following erro ...

Having trouble with data types error in TypeScript while using Next.js?

I am encountering an issue with identifying the data type of the URL that I will be fetching from a REST API. To address this, I have developed a custom hook for usability in my project where I am using Next.js along with TypeScript. Below is the code sni ...

Encoding and Decoding Base64 in Nativescript Using Angular 2

I've searched high and low for a solution but I can't seem to find one. Even after attempting to utilize atob() and btoa(), my efforts were futile. It seems that despite what intellisense suggests, these methods cannot be used. Additionally, plug ...

Tips for extracting individual fields from a payload in Angular 8

How do I extract individual fields from the payload and bind them with HTML on a page? I am trying to retrieve the alphacode and countryname in Angular 8. This is my Component: this.table$ = this.productService.get(id) .map(actions => { c ...

Angular 6 Universal does not pause for resolver completion

I recently completed the installation of Angular Universal start kit version 6 and designed my component within it. The main purpose of this component is to retrieve user information from an API upon loading and display it on the view. The issue I am faci ...

Filtering tables in Angular 6 using checkbox options

I have a functional code snippet that filters a table using checkboxes. However, I am facing an issue when unchecking a checkbox. It does not return the original array as expected. .html <ng-container *ngFor="let group of groups"> <label cla ...

Implementing real-time style changes with Angular 6 through Environment Variables

Attempting to dynamically change styles in Angular 6 using environment variables has been a success for me. Here is how my file structure is organized: src -app -assets -environments -scss -theme1.scss -theme2.scss -_variables.scss -styles.sc ...

After updating to ionic-native 2.5.1, encountering TypeScript Error TS1005 in Ionic 2

After updating to the latest version of ionic-native (2.5.1) in my ionic 2 project, I am encountering Typescript errors when running "ionic serve" in my terminal. I have attempted to update the typescript version to 2.x but to no avail. Any assistance woul ...

Endure the class attribute in Angular 5

My SearchComponent has a route (/search) and SearchDetailComponent has a route (/search-detail:id). In the SearchComponent, there is a searchbox (input field) where I can type any text to start a search. After loading the search results and navigating to ...

Trouble with loading images on Angular Application

After successfully building and deploying my Angular App using the build command on the cli with the deploy-url option as shown below: ng b -deploy-url /portal/ I encountered an issue where everything in the assets folder was showing up as 404 not found ...