Is there a way to showcase information contained within a subarray?

Can you assist me in retrieving data from a subarray? I am unsure how to go about it. Below is my code for your examination.

Here's the code from app.component.html:

<table class="table">
  <thead>
    <tr>
      <th scope="col">#</th>
      <th scope="col">First</th>
      <th scope="col">Last</th>
      <th scope="col">Title</th>
    </tr>
  </thead>
  <tbody>
    <tr *ngFor="let tableRow of table" (click)="open(tableRow)">
      <th scope="row">{{tableRow.id}}</th>
      <td>{{tableRow.first}}</td>
      <td>{{tableRow.last}}</td>
      <td>{{tableRow.title}}</td>
    </tr>
  </tbody>
</table>

<div *ngIf="bellowContent">
<p>id: {{ bellowContent.id }}</p>
<p>first: {{ bellowContent.first }}</p>
<p>last: {{ bellowContent.last }}</p>
<p>title: {{ bellowContent.title }}</p>
<p>hobbies: {{ bellowContent.hobbie || null }}</p>
<p>frequency: {{bellowContent.frequency}}
</div>

And here is my component's code:

app.component.ts

export class AppComponent {
  closeResult: string;
  bellowContent = [];
  table = [
  {
    "id": 1,
    "first":"Robin",
    "last": "William",
    "title": "back end developer",
    "hobbies": [
      {
        "hobbie": "tv",
        "frequency": "3 hours a day"
      },
      {
        "name": "game",
        "frequency": "2 hour per day"
      }
    ]
  },{
    "id": 2,
    "first":"Mark",
    "last": "Thornton",
    "title": "front end developer",
    "hobbies": [
      {
        "name": "tv",
        "frequency": "3 hours a day"
      },
      {
        "name": "game",
        "frequency": "2 hour per day"
      }
    ]
  },{
    "id": 3,
    "first":"Tary",
    "last": "Huction",
    "title": "front end developer",
    "hobbies": [
      {
        "name": "tv",
        "frequency": "3 hours a day"
      },
      {
        "name": "game",
        "frequency": "2 hour per day"
      }
    ]
  }
]

  open(tableRow) {
      this.bellowContent = tableRow
  }
}

You can also check out the full code on StackBlitz. Thank you for your support!

Answer №1

Displaying interests can be done in the following manner.

<table class="hobbies-table">
  <thead>
    <tr>
      <th scope="col">#</th>
      <th scope="col">Name</th>
      <th scope="col">>Description</th>
      <th scope="col">Level</th>
    </tr>
  </thead>
  <tbody>
    <tr *ngFor="let hobby of hobbiesList" (click)="showDetails(hobby)">
      <th scope="row">{{hobby.id}}</th>
      <td>{{hobby.name}}</td>
      <td>{{hobby.description}}</td>
      <td>{{hobby.level}}</td>
    </tr>
  </tbody>
</table>

<div *ngIf="selectedHobby">
<p>ID: {{ selectedHobby.id }}</p>
<p>Name: {{ selectedHobby.name }}</p>
<p>Description: {{ selectedHobby.description }}</p>
<p>Level: {{ selectedHobby.level }}</p>
Stats: 
  <ul>
    <li *ngFor="let stat of selectedHobby.statistics"> 
      {{stat.metric}}, {{stat.value}}
    </li>
  </ul>
</div>

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 provide a project name when using the angular material schematic?

My latest endeavor involved creating a brand new project workspace and then proceeding to establish an application and library within that workspace. ng new workspace --create-application=false cd workspace ng g library testlibrary ng g application playgro ...

Avoid assigning an `any` value in an unsafe manner, especially when using a custom hook function

export const useSpecificHook = () => { return useContext(OurContext); }; export const useCustomProcessor = () => { const [notes, setNotes] = useState([]); const removeItems = () => { setItems([]); }; return { clearNotes, } ...

Unable to eliminate UI component by clicking in Angular

I have been experimenting with different examples and attempted a few methods, but I am struggling to remove items from the UI level. I attempted to use the *ngFor directive, however, it seems to only remove <span> elements and not the <button> ...

Encountering a validation error when attempting to submit the form

I am facing an issue with my form. Inside the form, I have a dropdown menu that dynamically displays a textbox upon selection. The form also includes an array feature to allow for multiple textboxes to be displayed. Despite filling in all fields with value ...

Trouble encountered during installation of Angular CLI: module.js - code 549

I recently encountered issues with Angular-CLI, so I decided to update it using the command $ npm install -g @angular/cli. However, after doing so, I am facing a new error message. Can anyone provide assistance with this problem? module.js:549 throw err ...

How can I showcase an SVG icon received in base64 format using an img tag?

Having trouble displaying SVG/base64 encoded images through the img tag. Here is the issue at hand: Receiving iconData (as a string) from the server. Attempting to display it in my component. No issues with step 1. Encountering a broken image sign with s ...

Tips for resolving the issue of "The types 'GameState' and 'string' do not intersect, so this condition will always yield 'false'."

I need to display different components based on the value of gameStatus: import React from "react"; import { useAppSelector } from "./hooks/redux"; import EndScreen from "./pages/EndScreen"; import QuestionsPage from "./p ...

Angular - Directive unable to locate HTML element

I'm currently experimenting with creating pie charts in Angular 5 using a directive. Here's the directive I've set up: @Directive({ selector: '[pieChart]' }) export class PieChartDirective implements AfterViewInit { @Input() ...

Having trouble getting the embedded setInterval function to work properly within an observable in a test scenario

I've created a controller class for a countdown timer that is functioning correctly on the webpage, but I'm encountering issues with running my unit test. I am unsure if the problem lies in how I am executing the test or if there is an issue with ...

Ways to dynamically apply styles to the component tag depending on the visibility of its content

Consider a scenario where you have a component with logic to toggle the visibility of its contents: @Component({ selector: 'hello', template: `<div *ngIf="visible"> <h1>Hello {{name}}!</h1></div>`, styles: [`h1 { fo ...

Unexpected error encountered with the release of Angular 2: "Module import of 'ElementRef' resulted in an unexpected value"

After upgrading to Angular 2, I encountered an error related to ElementRef. Initially, I received the error message Angular2 RC5 error:zone.js: Unhandled Promise rejection: No provider for ElementRef which was discussed on this thread. I adjusted my code a ...

Create collaborative documents with serverless TypeScript extension

Utilizing Amazon Lambda AWS along with Serverless and the Serverless Plugin TypeScript to develop my TypeScript files has been quite a challenge. I have implemented shared code in my project, organized within folders such as: /shared: shared1.ts, shared2. ...

Encountering a TypeError with `useState` in a Next.js application while using a React/TypeScript library bundled with tsup

Currently, I'm in the process of developing a React-based component library and have hit a roadblock when integrating it with a Next.js application. I'm seeking advice or suggestions from this community on how to tackle this issue. Let me give yo ...

clicking a table row will activate the *ngFor directive

Incorporating data from an API into a table, I have enabled the functionality for users to click on table rows in order to change the displayed data using background code: <tr [ngClass]="tablerowClass" *ngFor="let dataObject of data$ | async" (click)=" ...

Guide on how to determine a true or false outcome post an HTTP request within an angularJS function

Environment AngularJS 4 I am currently trying to execute an HTTP Request within a function, but I am having trouble sending the result back. Below is my code with some comments. I am expecting either a true or false value, but unfortunately, I am receivin ...

Tips for effectively changing Observable data into an Array

I am currently attempting to transform an Observable into an Array in order to loop through the Array in HTML using ngFor. The Typescript code I have now is causing some issues. When I check the testArray Array in the console, it shows up as undefined. it ...

How to upload files from various input fields using Angular 7

Currently, I am working with Angular 7 and typescript and have a question regarding file uploads from multiple input fields in HTML. Here is an example of what I am trying to achieve: <input type="file" (change)="handleFileInput($event.target.files)"&g ...

Implementing an overlay feature upon clicking a menu item - here's how!

I am currently working on implementing an overlay that displays when clicking on a menu item, such as item 1, item 2 or item 3. I have managed to create a button (Click me) that shows an overlay when clicked. Now, I would like to achieve the same effect wh ...

Angular - Loading images on demand

I've recently started learning Angular and Typescript, and I've run into an issue that I could use some help with. I want to implement lazy loading for all the images in my application by adding the loading="lazy" attribute to each < ...

Please refrain from proceeding until the data recovery process is complete

I am currently facing a priority issue in my code. The problem arises when I call a web service and attempt to retrieve usernames based on user IDs from an array (listePasseoDemandesEnCours) using a foreach loop. this.ws_demandes_en_cours.getDemandesEnCour ...