Managing multiple HTTP requests in Ionic

I am having an issue with my http requests where I only receive the data from the first request and not all of them. Can anyone help me with this problem?

Thank you in advance for your assistance.

Here is my function:

async asyncCall() {
    return await this.subscription.push(forkJoin([this.http.get("https://pixabay.com/api/?key=15006679-5b02255bc032741ef0&q=phone wallpaper&per_page=200&min_height=200"),
            this.http.get("https://pixabay.com/api/?key=15006679-5b02255bc032741ef0&q=dog&per_page=200&min_height=200`"),
            this.http.get("https://pixabay.com/api/?key=15006679-5b02255bc032741ef0&q=cat&per_page=200&min_height=200`")
        ])
        .subscribe((data: any) => {

            // console.log("dtdtdt", data.map(e => console.log("e", e)))
            // console.log(data.length)
            for (let i = 0; i < data.length; i++) {
                return this.images = data[i].hits;
            }
        }))
}

This is how I'm displaying the images in my HTML:

<div [ngSwitch]="galleryType">
    <div class="images" *ngSwitchCase="'pinterest'">
      <div class="one-image" *ngFor="let image of images, let i = index"  tappable (click)="presentModal(i)">
        <img src={{image.webformatURL}}>
      </div>
    </div>
  </div>

Answer №1

One issue arises when you use the return statement within your loop, and don't forget to fix the typo pointed out by @cabesuon.

A better approach is to add the hits to your images array like this:

this.images = [];

for (let i = 0; i < data.length; i++) {
    this.images.concat(data[i].hits);
}

return this.images;

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

Having trouble with obtaining real-time text translation using ngx translate/core in Angular 2 with Typescript

Issue : I am facing a challenge with fetching dynamic text from a JSON file and translating it using the translate.get() method in Angular2. this.translate.get('keyInJson').subscribe(res => { this.valueFromJson = res; /* cre ...

Re-evaluating information when the query parameter is modified?

While working on my angular 2 projects, I encountered an issue where I couldn't reload the page by changing the query parameters within the same URL. I am currently utilizing resolve to fetch data before loading the page. I am now striving to figure ...

A step-by-step guide on uploading images to Firebase using Ionic 4

I'm having trouble uploading images to Firebase. Can anyone offer assistance? Does anyone know how to upload images to Firebase in Ionic 4.0? The code below used to work in Ionic 2, but now there's a delay of about 30 seconds after clicking the ...

Please anticipate the reply from the AngularJS 2 API

I want to insert a token into a cookie, but the issue is that the cookie is created before receiving the API response. How can I make sure to wait for the response before creating the cookie? My Implementation: getLogin() { this._symfonyService.logi ...

How can we eliminate the modal-open class in Angular when transitioning to a different URL?

Currently, I am facing an issue with a bootstrap modal. There is a button inside the modal which upon clicking should navigate the current component to another component named 'questions'. The problem arises when the new component is loaded, as t ...

How can I retrieve a targeted set of information from Firebase Realtime Database?

Any suggestions on how to improve querying a specific data set in Firebase RTDB? I've been using forEach() and pushing to a BehaviorSubject inside subscribe for each observable emitted. Share any alternative approaches you have! I've hit a roadbl ...

Weekday Filter in Angular 2

Looking to utilize the date pipe feature in Angular 2, specifically aiming for output that only includes the weekday name, such as "Wednesday." I am aware of the typical method to achieve this: {{ strDate | date :'fullDate' }} This would resul ...

Is there a method to implement retries for inconsistent tests with jest-puppeteer?

Currently, I am struggling with an issue where there is no built-in method to retry flaky tests in Jest. My tech stack includes Jest + TypeScript + Puppeteer. Has anyone else encountered this problem or have any suggestions for possible solutions? I attem ...

Creating a structure within a stencil web component

In my current project, I am utilizing Stencil.js (typescript) and need to integrate this selectbox. Below is the code snippet: import { Component, h, JSX, Prop, Element } from '@stencil/core'; import Selectr from 'mobius1-selectr'; @ ...

What are the steps to effectively implement the useEffect hook in React?

I'm facing an issue where I am trying to return a function that utilizes useEffect from a custom usehook, but I keep getting the error "useEffect is called in a function which is neither a react function component nor a custom hook." Here's what ...

What is the best way to target all select2 elements with a single button click?

Utilizing the Select2 feature of angular for multiple selection, I am in need of a function that allows me to select all elements with a single click on a button or checkbox. https://www.npmjs.com/package/ng-select2 My attempt at inserting all ele ...

The TypeScript compiler is unable to locate the module react-scripts within the lerna webpack configuration

Recently, I've been working on setting up a new project using lerna, react-scripts, webpack, and sass. Here is my current directory structure: myApp /packages /myReactApp -> a react create app application /tsconfig.json /package ...

I designed a dropdown menu with a searchable <mat-select> feature, where selecting an item is automatic when a space bar is pressed in the search box

Description : I have implemented a dropdown list using element that contains a list of items along with a search field. This allows users to easily search for specific items in the list instead of manually scrolling through a long dropdown menu. They can ...

Refresh child route independently without relying on data from parent route

I am currently facing an issue with my component 'panel' that has two child routes: dashboard and holidays. Both of these child routes are supposed to receive data from the parent component service in their ngOnInit. While everything is working ...

The unpredictable behavior of the `this` keyword while troubleshooting a TypeScript program in VS code

Upon further investigation, it seems that the issue I encountered was related to using Chrome for debugging my full application. This led me to question whether the problem stemmed from TypeScript or VS Code. Before submitting my findings, I decided to sw ...

What methods are most effective for transferring data into Excel?

Currently, I have a report data that is coming from a back-end service written in .NET and the report format is in an HTML table using Angular. I am looking to export this report to Excel using the Angular front end. What would be the most efficient ...

Are there problems with the response values of functions that can handle varying object interfaces?

Currently in the process of developing a command line blackjack app with Node and Typescript, even though I am relatively new to Typescript. My main challenge lies in implementing interfaces for player and dealer objects, as well as creating functions that ...

Encountering difficulties when transferring Angular2 example from Plnkr to a live application

Currently, I am attempting to integrate HighStocks into an Angular2 application by following the example provided in this plnkr link... http://plnkr.co/edit/2xSewTZ9b213vA0ALmFq?p=preview I am encountering a challenge in understanding how to include highs ...

Navigating json data in angular 6

I retrieved a JSON object in the following format response = [ { 'a': [ { 'b': [ { 'c': [ { 'name': 'abc', 'value': 900 ...

Passing an array of ID's between two components in Angular: A comprehensive guide

Greetings fellow readers, I have encountered a new challenge in my Angular project. I need to pass an array of IDs from one component to a completely unrelated component. Most solutions suggest using ViewChild, Input, or Output, but since the components ar ...