What is the process for displaying all items within an object in Ionic 3?

Perhaps my question is not very clear, but what I am attempting to do is when the Feed item in the categories screen is clicked, all companies related to Feeding will be listed on the companies screen.

I am quite confused because each category may have multiple companies and I am unsure how to list them properly. Can someone assist me?

The first image shows my category screen where clicking on the Feed item should display all companies related to the feed category.

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

The next image pertains to the Company page where all companies related to Food will be listed.

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

My items are stored as objects within my App.

Here is my home.html

    <ion-content id="#pageTop">
  <ion-searchbar (ionInput)="getItems($event)" placeholder="Search"></ion-searchbar>
  <ion-item *ngFor="let item of items">
    <ion-thumbnail item-left>
        <img [src]="item.imagem">
    </ion-thumbnail>
    <h2>{{ item?.category }}</h2>
    <button ion-button clear item-end color="primary" (click)="itemTapped($event, item)">Open</button>
  </ion-item>

  <ion-fab right bottom>
    <button ion-fab color="secondary" (click)="pageScroller()"><ion-icon name="ios-arrow-up"></ion-icon></button>
  </ion-fab>

And within my home.ts, this is where the objects are stored:

    initializeItems(){
    this.items = [
      { category: 'Food', imagem: '../../assets/imgs/food.jpg'},
    ]
  }

This is the part where I am uncertain, as I intend to add an array of type company in the object and include all the companies there, but duplicates of objects are not allowed.

For example:

 this.items = [
      { category: 'Food', imagem: '../../assets/imgs/food.jpg', company:'companyOne', company:'companyTwo'},
    ]

My company.html looks like this:

    <ion-item *ngFor="let company of company">
      <h2>{{ company?.category }}</h2>
    </ion-item>

And my company.ts is structured as follows:

   company: any[];
   constructor(public navCtrl: NavController, public navParams: NavParams) {
    this.company = this.navParams.get('item');
  }

Answer №1

It seems like you initially intended to include an array of company objects, but for some reason didn't follow through.

If I understand correctly, you may want to consider storing companies as an array within your item:

this.items = [
    {   
        category: 'Alimentação', 
        imagem: '../../assets/imgs/alimentacao.jpeg', 
        companies:[{ /*first company object*/}, {/*second company object*/}]
    }];

To display the associated companies with an item, you could do something like this:

<ion-item *ngFor="let item of items">
    <ion-item *ngFor="let company of item.companies">
        <h2>{{ company?.category }}</h2>
    </ion-item>
</ion-item>

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

How to modify a variable within the "beforeSend: function()" using Ajax and jQuery

I am facing an issue with my ajax contact form. The beforeSend function is supposed to validate the inputs and pass the parameters to a PHP file for sending emails. However, I always receive false instead of true even when the inputs are valid. I suspect ...

Can CSS be altered dynamically in Laravel blade?

Is there a way to dynamically change CSS? I am trying to set the class=sheet padding-top: 28mm; when the size of $anArray is less than 30. If the array has more than 30 elements then apply padding-top: 28 * 2 mm;. Finally, if the array exceeds 60, use pad ...

What could be causing the TypeScript exhaustive switch check to malfunction?

How come the default case in the switch statement below does not result in an exhaustive check where 'item' is correctly identified as of type 'never'? enum Type { First, Second } interface ObjectWithType { type: Type; } c ...

Unable to target a dynamic div and utilize solely its image

Can someone provide some assistance with a jQuery issue I am facing? I have a lengthy list of images directly uploaded from YouTube, each image has the same "v-code" as its corresponding video. To simplify the downloading process for all videos on one page ...

Changes in content result in modifications to the size of transition elements

Have you ever encountered a button with changing text upon being pressed? The transition in text leads to a shift in the button's width. Wouldn't it be amazing if one could smoothly transition the change in width of an element using a code snippe ...

Ways to display a collection of random images with a click of a button?

I've created a simple php webpage that is supposed to display random images from my images folder when a button is clicked. However, I'm facing an issue where no images are showing up and I can't seem to pinpoint the problem in my code. ...

SystemJS could not locate the root directory for RxJS

There seems to be an issue with SystemJS loading rxjs modules on Windows, as it throws a 404 Not Found error on the rxjs directory. This problem does not occur on OSX, and all modules are up to date. GET http://localhost:8080/node_modules/rxjs/ 404 (Not F ...

An issue arose during resolution... Angular Library unable to resolve dependency

As I embark on creating my very first component library, things have been progressing smoothly. Now, I am at the stage where I am testing the library by incorporating it into new projects. The package.json file for my library project is set up as follows ...

Tips for adjusting the property of an object that has been added to an array?

I have created an object. { "heading": [{ "sections": [] }] } var obj = jQuery.parseJSON('{"header":[{"items":[]}]}'); Then I add elements to the sections var align = jQuery.parseJSON('{"align":""}'); obj["he ...

What is the process for filling a table with data sourced from Firebase?

I have successfully used the code below to populate a datatable table with data from a JSON file. However, I am now attempting to populate the table with data from Google's Firebase database. The issue arises because new data pushed into Google's ...

During the rendering process, the property "instance" was attempted to be accessed but is not defined

I am having trouble creating a Contact Us page using v-model. My code keeps throwing these errors: Property "inputted_name" was accessed during render but is not defined on instance Property "inputted_email" was accessed during render but is not defined o ...

When I attempt to click on the Cancel button, the database row remains undeleted

After a user clicks on the "Cancel" button, I want to reset the source and remove the iframe to prevent the file from being uploaded to the server. This function is currently working as intended. However, I am facing an issue where even after clicking on ...

Shifting a div from side to side

I don't have much experience with coding, so I was hoping for some assistance. My goal was to create a div that moves back and forth using toggleClass; $('div').on('click', function() { $(this).toggleClass('active') ...

Do you want to reset the validation for the paper input?

I am encountering an issue with a paper-input element in my code. Here is what it looks like: <paper-input id="inputForValidation" required label="this input is manually validated" pattern="[a-zA-Z]*" error-message="letters only!"></paper-input&g ...

showing information from a table column

Utilizing the jQuery DataTables plugin with a JSF <h:dataTable>. The page contains 86 records. +++++++++++++++++++++++++++++++++++++ + SN. + Name + Email + +++++++++++++++++++++++++++++++++++++ + 1 + Name 1 + Email 1 + + ...

SignalR's postback interrupts the functionality of jQuery actions

On my screen, I have a widget that updates data and changes its class based on server-side interactions. It also responds to mouse clicks. To notify multiple clients of updates simultaneously, I'm using SignalR. The problem arises when I wrap everythi ...

Tips for creating an endless loop within a nested v-for in Vue?

Here is my attempt at solving the problem: HTML <ul class="tree"> <li> <span>First Node</span> <ul> <li v-for="(tree, i) in trees" :key="i"> <span v-text="tree. ...

How should the superclass constructor of `MatDialog` be invoked when working with multiple classes?

When dealing with multiple features in my ts file, I decided to split them into separate classes. constructor( ) { super(MatDialog); } Encountered error: Argument of type 'typeof MatDialog' is not assig ...

How come the parameters in my function are being displayed as boolean values in JSDocs when that is not the intended behavior?

I am documenting my journey of following the React tutorial for tic-tac-toe, and I'm puzzled as to why the parameters of my function are showing up as boolean values in JSDocs when they are not supposed to. When I hover over the function with my curs ...

One of the functionalities is not functioning properly: either the validation or the AJAX

My validation code was working fine until I added some ajax code. Now, when I include the onclick="return chk()" in the submit input field, the validation code stops working. But if I remove it, the ajax code doesn't work. How can I resolve this issue ...