Exploring Objects within an Array in Ionic 2 and AngularJS 2

I am currently working on displaying reviews obtained from a Laravel API, showcasing feedback on various meals. The goal is to create a slideshow of review messages along with additional data as presented in the array of Objects below:

{

    "2": {
        "reviews": [
            {
                "id": 2,
                "title": "Trop bon !",
                "author": 1,
                "text": "Trop bon ! 11 Trop bon !Trop bon !Trop bon !Trop bon !",
                "picture": "",
                "rating": 4.5
            },
            {
                "id": 3,
                "title": "Review 2",
                "author": 1,
                "text": "another review",
                "picture": "",
                "rating": 3
            }
        ],
        "data": {
            "restaurant": {
                "restaurant_id": 1,
                "restaurant_logo": "http://3.bp.blogspot.com/-Oz5XdPqGddQ/ULy9zwbIDXI/AAAAAAAAPio/HZwYtIr7DfE/s1600/22-restaurant-logo-design.jpg",
                "restaurant_title": "Resto BenArus",
                "restaurant_type": "Fast Food",
                "restaurant_lat": "36.7465169",
                "restaurant_lng": "10.2171373",
                "user_distance": 9.3072696748262
            },
            "meal": {
                "id": 2,
                "meal_title": "Spaghetti Bolonaise",
                "price": 50,
                "meal_description": "Epic !",
                "reviews_count": 2,
                "overall_rating": 3.75
            }
        }
    },
    "3": {
        "reviews": [
            {
                "id": 4,
                "title": "Total",
                "author": 1,
                "text": "cristifant ",
                "picture": "https://www.gravatar.com/avatar/d9625431c20a1565a2e06f811a95c36c?s=140&d=retro",
                "rating": 3
            }
        ],
        "data": {
            "restaurant": {
                "restaurant_id": 2,
                "restaurant_logo": "http://3.bp.blogspot.com/-Oz5XdPqGddQ/ULy9zwbIDXI/AAAAAAAAPio/HZwYtIr7DfE/s1600/22-restaurant-logo-design.jpg",
                "restaurant_title": "resto 2",
                "restaurant_type": "Fast Food",
                "restaurant_lat": "10",
                "restaurant_lng": "32",
                "user_distance": 3701.7730713836
            },
            "meal": {
                "id": 3,
                "meal_title": "Hamburger",
                "price": 12,
                "meal_description": "",
                "reviews_count": 1,
                "overall_rating": 3
            }
        }
    }

}

A Pipe was created for iterating through the results:

   transform(value, args:string[]):any {
    let keys = [];
    for (let key in value) {
      keys.push({key: key, value: value[key]});
    }
    return keys;
  }

However, the output is not ideal, as it only displays the initial keys from the array:

https://i.sstatic.net/utNdp.png

The way the data is being shown might not be correct:

    <ion-content padding>
  <ion-list *ngFor="let data of search | keyobject " no-lines>
    <ion-list *ngFor="let data2 of data | keyobject " no-lines>
      <ion-item>Value: {{ data2.value }} {{ data2.key }}</ion-item>
      <ion-list *ngFor="let data3 of data2 | keyobject " no-lines>
        <ion-item>Value: {{ data3.value }} {{ data3.key }}</ion-item>
      </ion-list>
    </ion-list>
  </ion-list>
</ion-content>

Answer №1

<section id="food-gallery">
    <div class="row">
        <div class="col-6">
          <div class="card-item">
             <div class="gallery">
                <div *ngFor="let item of meals | ArrayObject " class="slide">
                    <img src="{{item.value['picture']}}" alt="">
                    <h2>{{item.value['title']}}</h2>
                    <p>By {{item.value['author']}}</p>
                </div>
            </div>
         </div>
      </div>
      <div class="col-6">
          <div class="card-content">
              <h3>{{data.value['meal']['title']}}</h3>
              <p>
                  <small><rating [score]="data.value['meal']['overall_rating']" [max]="5"></rating> ({{data.value['meal']['reviews_count']}}) Reviews</small>
               </p>
           </div>
      </div>
     </div>
  </section>

This revised code snippet uses array elements as values to display meal reviews in a gallery format. By utilizing the data.values, the transformation is done on known elements once they are accessed.

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

Unexpected problem following Ionic 2 update in Npm

Encountering an error while attempting to initiate a new app project in Ionic 2 using the following command: ionic start name blank --v2 The error message is as follows: One awesome Ionic app coming right up... Downloading: https://github.com/driftyco/ ...

React components need to refresh after fetching data from an API

I am currently working on a React application using TypeScript and integrating JSONPlaceholder for simulating API calls. I have successfully set up everything I need, but I am encountering an issue with re-rendering components that display response data fr ...

Mocking store.dispatch in Jest with TypeScript did not result in any function calls being made

Testing Troubles I'm a beginner in the world of testing and I'm facing some challenges. Despite going through all the documentation on jest, I couldn't find information specific to TypeScript cases. Currently, I'm on a quest to figure ...

Adding an interface for an object containing multiple objects requires defining the structure and behavior

I'm in the process of designing an interface for my object. Here is the data structure of the object: { "isLoaded": true, "items": { "0": { "name": "Mark", "age": "40" }, "1": { "name": " ...

Creating HTML content in TypeScript with NativeScript using document.write()

Essentially, I am looking to create a set number of labels at various row and column positions depending on the user's input. However, I have been unable to find any resources that explain how to write to the .component.html file from the .component.t ...

A guide on updating an Observable with a value retrieved from another Observable

Struggling to find a way to update the result of one Observable with the result of another. Can anyone provide guidance on how to do this without nested subscriptions and return the resulting Observable for later use? this._http.get<JSON>(url, { pa ...

Error encountered in Angular/Ramda while using mapAccum with an array of objects in Typescript

I am having difficulties implementing Ramda in an Angular 6 / TypeScript environment. "ramda": "^0.25.0", "@types/ramda": "^0.25.24" This is how I have started: const addP = (p1,p2) => ({ x: p1.x+p2.x,y: p1.y+p2.y }); const accum = (a,b) => [add ...

Having trouble with Visual Studio 2015 not compiling TypeScript within an ASP.NET Core project?

Seeking assistance with my Angular app development setup in VS2015. Even though it is recognized as a TypeScript Virtual Project, I am facing issues getting the transpiled files into the wwwroot folder within my ASP.NET Core project. Here's an overvie ...

Issue: Debug Failure. Invalid expression: import= for internal module references should have been addressed in a previous transformer

While working on my Nest build script, I encountered the following error message: Error Debug Failure. False expression: import= for internal module references should be handled in an earlier transformer. I am having trouble comprehending what this erro ...

Set the styling of a div element in the Angular template when the application is first initialized

I have a question about this specific div element: <div class="relative rounded overflow-clip border w-full" [style.aspect-ratio]="media.value.ratio"> <img fill priority [ngSrc]="media.value.src || ftaLogo" ...

An unexpected error occurred in the file node_modules/@firebase/firestore/dist/index.d.ts at line 27:28 - Please insert a ']' at this location

When adding firebase to my Angular app, I encountered an error while running ng serve: ERROR in node_modules/@firebase/firestore/dist/index.d.ts:27:28 - error TS1005: ']' expected. 27 [K in keyof T & string as `${Prefix}.${K}`]+?: T[K]; ...

Obtain item from DataSource in Angular's MatTable

In my transaction-history.component.ts file, I have implemented a material data table that fetches data from a query to display it. Here is the code snippet: import { Component, OnInit } from '@angular/core'; import { Transaction } from '.. ...

What's the process for deducing the default generic parameter from a function type?

Is there a way to extract the default type parameter of a function in order to make this statement compile successfully? const fails: string = "" as ReturnType<<T = string>() => T>; ...

Facing a challenge with handling HTTP data in a TypeScript-based Angular web application

I am currently working on developing a web application using Angular and the SpringMVC Framework. One of the tasks I'm facing is loading a list of users (referred to as "consulenti" in the code). While the backend HTTP request works fine, I encounter ...

DOM Manipulation in Angular

I encountered an issue in the spec file where DOMHelper was not found and could not be imported, despite adding it with "npm I dom-helpers". How can I resolve this error? I will also provide a screenshot for reference. Click here to view the image Module ...

Messages are not being emitted from the socket

I've been encountering an issue with message transmission from client to server while using React and ExpressJS. When I trigger the sendMessage function on the client side, my intention is to send a message to the server. However, for some reason, the ...

What could be causing the Typescript error when utilizing useContext in combination with React?

I am currently working on creating a Context using useContext with TypeScript. I have encapsulated a function in a separate file named MovieDetailProvider.tsx and included it as a wrapper in my App.tsx file. import { Context, MovieObject } from '../in ...

NGINX: Serving as a proxy exclusively for upstream requests

I have a scenario that I'm hoping to get some assistance with. The setup involves hosting multiple Angular projects on nginx using a single URL with path extensions to distinguish between the sites. Here's an example snippet of the configuration: ...

Pictures are shown using the "text/html" layout

I'm having trouble identifying the error and have decided to carefully examine both the client and server code. It seems likely that there is a bug somewhere in Rails. The issue revolves around the photos being displayed in text/html format. Here&apos ...

Form remains unchanged after manipulation in callback

Currently, I have a form with a list of editable objects (constants). Previously, it was possible to delete any object without confirmation. Now, I want to add a ngBootbox confirm step before the deletion process. In my .ts file, the code for deleting an ...