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.

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

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

The scroll function triggers even upon the initial loading of the page

Trying to solve the challenge of creating a fullscreen slider similar to the one described in this question, I created a jsfiddle (currently on hold) Despite knowing that scrolling too fast causes bugs and that scrolling both ways has the same effect, m ...

Enhance the interoperability of Babel with Express.js by steering clear of relative

My current approach to imports is as follows: import router from '../../app/routes' Is there a way to avoid using ../../, for example: import router from 'app/routes'? In typescript, I can achieve this with the following configuratio ...

Error message in Visual Studio 2017: Identical name 'URLs' declared twice in

In our Visual Studio 2017 project, we have multiple TypeScript files that define a URLs class. Each file contains different implementations of the class to change site URLs based on the specific use case: customer/urls.ts namespace Portal { export cl ...

Getting the latest data from a Kendo Dialog in Angular 4

I am passing the 'TotalUnits' value to the Dialog and updating it there. However, I am having trouble retrieving the updated value back in the 'dialog.result'. Can anyone provide some assistance? Main Component: Open AllocationDialog( ...

struggling to send variables to jade templates with coffeescript and express.js

As a newcomer to node and express, I am currently building the front end of an application that utilizes jade as its templating engine. Despite extensive searching online and within this community, I have not been able to find a solution to a particular is ...

Learning how to dynamically update a value in Angular based on user input

My goal is to dynamically change the output value based on user input using Angular. I have successfully implemented the functionality to increment the value, but unfortunately, when the input changes, the outputed value remains static. Below is my curren ...

React canvas losing its WebGL context

What is the best practice for implementing a webglcontextlost event handler for React canvas components? class CanvasComponent extends React.Component { componentDidMount() { const canvasDOMNode = this.refs.canvas.getDOMNode(); DrawMod ...

What are the implications of a project containing nested node_modules directories?

We are currently in the process of dividing our project into "sub modules" within a single repository. Our goal is to maintain aspects such as webpack configurations and express server globally, with a structure similar to the following: package.json serv ...

Error message: "User not found during passport authentication"

I am currently in the process of developing an authentication system for my website. However, I am encountering a specific error message when attempting to log in with any combination on the website: ReferenceError: user is not defined user is not define ...

Error: Unable to establish connection - Asp.Net Core and Angular 10

Currently, I am following an Asp.net tutorial along with using the Angular server with CORS package integration. My main goal is to make a post request: // POST: api/Trackers // To protect from overposting attacks, enable the specific properties y ...

Is it possible to view the original source code by simply clicking ctrl + click?

Currently, I am working on a project involving TypeScript and Angular, utilizing the library Spartacus. Often times, I find myself needing to reference the source code. This is how I currently go about it: I come across StateUtil from @spartacus/core, th ...

The renderValue property is malfunctioning in the Material-UI native Select component

Whenever I utilize the native prop in the MUI Select component, the renderValue prop fails to function properly. Additionally, if I attempt to assign a custom value to the value prop, it does not display. Take a look at the code snippet below: const [selec ...

Generate an image instantly from text using ajax when a key is pressed

Currently, I am immersed in a stencil project where my goal is to convert text into an image. In this particular task, there's a textbox that captures the user input on key up event. Once the user enters text, my aim is to display that text as an imag ...

Typescript implementation for a website featuring a single overarching file alongside separate files for each individual webpage

Although I've never ventured into the realm of Typescript before, I am intrigued by its concept of "stricter JS". My knowledge on the subject is currently very limited as I am just starting to experiment with it. Essentially, I have developed my own ...

What is the correct way to upload an image using the Express static middleware?

Just diving into express, I have this setup in my server: app.use(express.static(path.join(__dirname, 'includes'))); When it comes to my client-side JavaScript, I'm simply using the URL like so: var img = $("<img />").attr('s ...

Run a PHP statement when a JavaScript condition evaluates to true

I am attempting to run a php statement if my javascript condition is true. Here is the code snippet that I have written: <input id="checkbox1" type="checkbox"> MSI<br></input> <script> $(document).ready(function(){ $(&apos ...

Converting string to JSON format by splitting it based on names

I recently manipulated a string containing the values "title:artist" by utilizing the str.split method : res = song.split(":"); The resulting output is as follows: ["Ruby","Kaiser Chiefs"] Now, I am curious about how to include the name in this array f ...

Transmit information to Component via Modal Service

I am utilizing a Modal Service in Angular 7. To see an example, check out this StackBlitz Example. The service is used as follows: export class AppComponent { constructor(private modalService: ModalService) { } openModal() { this.modalService.o ...

Error with AngularJS: IE not showing dropdown options for MultiSelect

My application features a multiselect dropdown menu that shows a list of countries. While this dropdown functions correctly in Chrome, it displays options differently in IE as shown below: https://i.stack.imgur.com/xhOmV.png I have attempted to adjust th ...

Show the res.send() method from express.js without replacing the existing html content

Currently, I am in the process of developing a calculator application using express.js. The app needs to handle get requests for an HTML file and post requests that capture user input and provide the response accurately. My challenge lies in showcasing the ...