What is the method for displaying an object within an HTML template by accessing its keys?

I need to display an object in a modal. When the read more button is clicked, it should send the title name and Amazon link to a function that will pass them to the modal. However, ngFor doesn't seem to display the object, and only one object is sent at a time. I just need to show the object like {{modal.name}} using the key and value in the HTML template.

/*Function*/
readMore(text: string) {
    this.modal = text;
 }
  <h1 class="uk-flex uk-flex-center uk-width-1-1">{{book.list_name}}</h1>
  <hr class="uk-divider-icon uk-width-1-1">
  <div class="uk-grid uk-grid-divider textali">
  <div class="uk-width-1-3">List Updated {{book.updated | lowercase }}
  </div>
  <div class="uk-width-1-3">
    <a href="#offcanvas-usage" class="uk-button uk-button-primary" uk-toggle>Categories</a>
  </div>
  <div class="uk-width-1-3">List Published On {{book.published_date | lowercase |date: 'fullDate'}}
  </div>
</div>
  <div class="uk-grid uk-grid-medium" >
  <div class="uk-child-width-1-5@s uk-grid-match" uk-grid>
    <div *ngFor="let name of book.books; let i = index">
      <div class="uk-card uk-card-hover uk-card-body">
        <img src="{{name.book_image}}"><br /><br />
        <span>Summary: {{name.description || ' NA'}}</span><br />
        <hr class="uk-divider-icon">
        <span>Author {{name.author}}</span>
        <br />
        <br />Best Sellers Rank {{name.rank}}
        <br />
        <span>Weeks on List {{name.weeks_on_list}}</span>
        <div class="uk-card-footer">
          <a href="{{name.amazon_product_url}}" class="button uk-icon-link uk-margin-small-right" uk-icon="icon: cart; ratio: 1.5"></a>
         <span><a class="uk-icon-link uk-margin-small-right" (click)="addFav({title: name.title, image:name.book_image, amazon:name.amazon_product_url})" uk-icon="icon: heart; ratio: 1.5"></a></span>                   /*This is the data being sent*/
          <a (click)="readMore({name: name.title, desc:name.description, author:name.author})" uk-toggle="target: #read-more" class="uk-icon-link uk-margin-small-right" uk-icon="icon: info; ratio: 1.5"></a>
        </div>
      </div>
    </div>
  </div>
</div>
<div id="offcanvas-usage"  uk-offcanvas>
  <div class="uk-offcanvas-bar">
    <button class="uk-offcanvas-close" (click)="this.isButtonVisible = true" type="button" uk-close></button>
    <h3>Categories</h3>
    <div *ngFor="let section of names">
      <div class="uk-flex uk-flex-column">
        <ul class="uk-nav uk-nav-primary uk-nav-center uk-margin-auto-vertical">
          <li class="uk-active"><a (click)="sectionlink(section.list_name)">{{section.list_name}}</a></li>
        </ul>
      </div>
    </div>
  </div>
  </div>
  <div id="read-more" uk-modal>
    
      <div class="uk-modal-dialog uk-modal-body">
          /*Where the Data gets displayed*/
          <h2 class="uk-modal-title">{{item.name}} </h2>
          <hr class="uk-divider-icon">
          <hr class="uk-divider-icon">
          
          <button class="uk-modal-close uk-button uk-button-danger" type="button">Close</button>
          </div>
  </div>

Answer №1

If you want to transform an Object or Map into an array of key value pairs, you can use the keyvalue pipe. Simply use it like this:

*ngFor="let o of object | keyvalue"

Here's an example:

<th *ngFor="let o of object | keyvalue">{{o.key}}{{o.value}}</th>

For more information on the keyvalue pipe, you can visit this link

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

The mysterious connection between Angular and the magic of markForCheck() in updating views

It seems to be widely accepted that the markForCheck function simply flags the current component view and all parent components (up to the root) as needing updating. When the DetectChanges function runs, it will refresh the view accordingly. Now, in a scen ...

ngx-slider dynamic positioning of the ceiling value

https://i.sstatic.net/aLBtd.png I am currently facing an issue with maintaining consistent placement of the 'infinity sign' across different screens. It appears that the offset is determined within the slider component code. The icon's posi ...

Injecting HTTP_PROVIDERS in Angular2 rc.5 is a breeze now that Http is a module

Looking for a way to inject HTTP_PROVIDERS in Angular2 rc.5 now that everything is in modules... var injector = ReflectiveInjector.resolveAndCreate( [ TodoService, TodoAction, HTTP_PROVIDERS, // ...

Working with nested arrays in TypeScript and how to push values onto them

I am facing some challenges with nested array behavior in TypeScript. I am looking for a way to define a single type that can handle arrays of unknown depth. Let me illustrate my issue: type PossiblyNested = Array<number> | Array<Array<number& ...

Stop MatDialog from closing automatically when clicked outside while there are unsaved changes

Is there a way to prevent closing when there are pending changes without success? this.dialogRef.beforeClosed().subscribe(() => { this.dialogRef.close(false); //some code logic //... }); The setting disableClose on MatDialog must remain as false ...

Dealing with Errors in Angular 5 using Observables: Why Observable.throw isn't working

Can someone assist with resolving this issue? Error message: core.js:1542 ERROR TypeError: rxjs__WEBPACK_IMPORTED_MODULE_3__.Observable.throw is not a function Software versions: Angular CLI: 6.0.8 / rxjs 6.2.1 import { Injectable } from '@angular/ ...

Navigating to the Login page in Angular 13

<app-navbar></app-navbar> <div class = "app-body"> <div class="app-sidebar"> <app-sidebar></app-sidebar> </div> <div class="app-feed"> <router-outlet name="main& ...

Printing in HTML with Angular based on certain conditions

As I cycle through a list of products, I am verifying if the product Id is already included in an array of products (objects). If it is, then I print the quantity. If not, I attempt to print 0. Here is the code snippet I have been working on: <ion-item ...

What steps can be taken to resolve the TS5023 error that arises when including "allowImportingTsExtensions" in the tsconfig.json file?

While working on my React project, I've encountered a specific error that reads: Could not parse tsconfig.json. Please ensure it contains valid JSON syntax. Details: error TS5023: Unknown compiler option 'allowImportingTsExtensions'. I tr ...

The function cloneElement does not share any properties with the type Partial<P> and Attributes

I'm encountering a perplexing issue with my code. When I attempt to call cloneElement with the second parameter being of type Type { foo: number } has no properties in common with type 'Partial<Child> & Attributes', TypeScript thro ...

When using the listServiceLevelObjectives function, an UnhandledPromiseRejectionWarning occurs: The error message returned is "3 INVALID_ARGUMENT

Hey there, I'm struggling to retrieve a list of SLOs in my Google Cloud project via the REST API using TypeScript. Unfortunately, I keep running into an error message. Could you lend me a hand with this? The error reads: (node:47173) UnhandledPromis ...

Why is my Express/Angular POST request failing due to CORS?

After exhausting all my ideas and conducting thorough searches, I still feel like I have not found the solution. https://i.sstatic.net/2xJPh.png The code in its "clean" form is presented below: Server.js - Express const express = require('express& ...

Why isn't the constraint satisfied by this recursive map type in Typescript?

type CustomRecursiveMap< X extends Record<string, unknown>, Y extends Record<string, unknown> > = { [M in keyof X]: M extends keyof Y ? X[M] extends Record<string, unknown> ? Y[M] extends Record<st ...

Strategies for sending data to ng-container through ngTemplateOutlet

Currently, I am delving into mastering Angular directives and I am facing an issue with passing a value to my component. Here is the code snippet: My Component ` @Component({ selector: 'app-my-one', template: ` <ng-container *n ...

What are the types of tuple lookups using mapped types in TypeScript

Since the introduction of mapped tuple types in typescript 3.1, I was eager to see if this code sample would function as expected: export interface SettingKey { General_Language: 'en' | 'sl'; Map_InitialLongitude: number; M ...

Utilizing Angular 4 with PrimeNG Menu - Highlighting Multiple Menu Items as Active

I have implemented Angular version 4.1.2 along with PrimeNG version 4.3.0 The problem I am encountering is related to the PanelMenu or p-panelMenu component. Below is the structure of my Menu: { label: 'Demo', icon: 'fa-shield& ...

Module 'ngx-bootstrap' not found in project

My application is encountering an issue with ngx-bootstrap where the module can no longer be detected unless the path is specified. For instance: import { BsModalService, BsModalRef } from 'ngx-bootstrap'; results in "Cannot find module ' ...

What is the best way to open a new page on top of the current page using Angular2?

On the left side of my page, I have two menu items - "Dashboard" and "Resource request". You can easily switch between them by clicking on each item. Both pages are separate components. I'm looking to change the functionality a bit. I want to add a b ...

Ways to utilize a previous acquisition

After purchasing a consumable product, I forgot to consume it during my release. I made changes to my code so now the unpurchased products are not available for purchase anymore. When I attempted to use restorePurchases to consume the products that were n ...

Stop allowing the entry of zero after a minus sign

One of the features on our platform allows users to input a number that will be automatically converted to have a negative sign. However, we want to ensure that users are unable to manually add a negative sign themselves. We need to find a solution to pre ...