Learn the steps to retrieve an array containing images within an Angular Modal Gallery

In my Angular application, I am working on creating an image gallery using 'angular-modal-gallery'. The main challenge I am facing is how to convert the observable containing image data from the media service into an array. According to the documentation of angular-modal-gallery, I need to initialize an array with the images.

media.service.ts

export class MediaService {

  API_URL = AppConfig.settings.api.url;
  constructor(private http: HttpClient) { }

  getAlbum = (id: string) => {
    return this.http.get(`${this.API_URL}/album?id=${id}`);
  };
}

component.html

<modal-gallery [modalImages]="imagesArraySubscribed"></modal-gallery>

component.ts

export class PhotoComponent implements OnInit {

  imagesArraySubscribed: Array<Image>;
  private subscription: Subscription;

  private album_id = '12121564564564';
  private album$: Observable<any>;

  constructor( private mediaService: MediaService ) { }

  ngOnInit() {

  this.album$ = this.mediaService.getAlbum(this.album_id).pipe(map(res => 
  res['photoset']['photo']));
   }
 }

Answer №1

In order to retrieve images from an album, you need to subscribe to the media service and push the received photos to an array.

Make sure to use the map operator to extract the 'photo' data from the response before pushing it to the array.

Answer №2

To access the album data, you need to subscribe to the getAlbum method.

this.album$ = this.mediaService.getAlbum(this.album_id).suscribe( (res:any[]) => {
    this.imagesArraySubscribed = res['photoset']['photo']; 
}

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

Guide on setting up a chart using data fetched from an API?

I'm looking to incorporate ngx-charts into my project, but I'm struggling with initializing the chart with data retrieved from my API. Setting up a vertical bar chart seems straightforward. The data structure I have is like this: https://stackb ...

What is the process for implementing a new control value accessor?

I have a directive that already implements the ControlValueAccessor interface (directive's selector is input[type=date]) and now I need another directive that also implements ControlValueAccessor with the selector input[type=date][datepicker] - let&ap ...

Issue with nestjs build due to ts-loader module in dev-dependency

I've encountered a Module Error with ts-loader during a docker build ERROR [6/6] RUN nest build 3.9s ------ > [6/6] RUN ...

Automatic Form Saving in Angular 4

Seeking to create a form data autosave feature in Angular 4. The functionality should operate as follows: User modifies data in the form -> save request sent to DB. A timer is initiated for 2 seconds. During the 2-second window after the previous s ...

Angular FILE Input Modal

I am currently working on a personal project, which is a social networking platform where users have the ability to create, modify, and delete posts, as well as comment on each post. My development work is focused on Angular at the moment. Within my post ...

Having trouble modifying the value of a textBox with ngModel and a directive

Having trouble trimming a text input and ending up with duplicate values https://i.sstatic.net/PkrxB.png New to Angular, seeking help in finding a solution View Code on StackBlitz ...

What steps should I follow to bring a telegram bot to life? Is it an issue if I try to integrate a module from Deno

import { TelegramBot, UpdateType } from "https://deno.land/x/telegram_chatbot/mod.ts"; <--- ISSUE import "https://deno.land/x/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c6a2a9b299a3a8b086f6e8f4e8f6"> ...

Personalized design for Material Tooltip in Angular 17

I am currently working on an angular 17 application that utilizes the latest Material components. My project heavily incorporates the Tooltip component, but I am facing challenges when it comes to customizing it to my preferences. While I did succeed in c ...

Leveraging server.ts for Development with Angular 5 Universal

I decided to give the new Angular Universal Starter a try for my latest Angular 5 project. Instead of providing multiple options, they now only offer the Angular CLI version as a starting point. I've been able to successfully run my project in product ...

I'm struggling with deleting a row from a pushed Object in Angular 2 and could use some guidance

Let me start by explaining my current issue: Initially, the problem was like this: , where it deleted the last created Object, Conditions in my case. However, I need to be able to delete each condition separately. For example, as shown with the red box n ...

Determine the presence or absence of data in an Angular Observable

Here is an example of how I am making an API call: public getAllLocations(): Observable<any> { location = https://v/locations.pipe(timeout(180000)); return location; } In my appl ...

Tips for preventing the impact of angular mat-panel position changes on matdialog

In my Angular project, I utilized Matmenu and MatDialogModule. I needed to change the position of mat-menu, so I achieved this by adding the following snippet to my .scss file. ::ng-deep .cdk-overlay-pane { transform: translate(78%, 10%); } However, ...

Step-by-step guide for adding an object to a Material UI select component

I am in the process of incorporating a Select component with reactjs material ui and typescript. Yet, I encounter this typing error: Property 'id' does not exist on type 'string'. Property 'name' does not exist on type ' ...

TypeScript does not automatically deduce types

Here is a function I am working with: type DefaultEntity = { id: string; createdBy: string; [fieldName: string]: unknown; }; abstract find<T, Schema extends string | (new () => T)>( schema: Schema, id: string, ): Promise<(Schema ...

Ways to Obtain Device Identification in Ionic 2 Utilizing TypeScript

Can anyone help me with getting the device ID in ionic2 using typescript? I have already installed the cordova-plugin-device Here is my code snippet: platform.ready().then(() => { console.log(device.cordova); } Unfortunately, this code doesn&apos ...

Issue encountered while utilizing an observable object within a FormGroup

I've encountered an issue that I can't seem to resolve. I have a function that is responsible for creating my FormGroup along with the form fields and validators. The validators are custom validators that require a value from an observable, and t ...

Is it possible to effectively utilize NgRx with Promises rather than Observables?

In my experience, I have primarily encountered NgRx being utilized with Observables. However, I am curious to know if the NgRx library can easily work with promises in the same way as it does with observables. Currently, I am working with Ionic 5 and have ...

Sending an object between two components without a direct parent-child connection

Hello, I have a question similar to the one asked on Stack Overflow regarding passing a value from one Angular 2 component to another without a parent-child relationship. In my scenario, Component1 subscribes to a service that makes a GET request to the ...

The code compilation of Typescript in a Dockerfile is not functioning as expected due to the error "Name 'process' cannot be found."

Here's the Dockerfile I'm working with: FROM node:latest WORKDIR /usr/src/app ENV NODE_ENV=production COPY package*.json . RUN npm install && npm i -g typescript COPY . . RUN tsc CMD [ "node", "./dist/index.js&qu ...

What is the best way to send information to a child component that has been navigated from a parent component

When navigating to a child component from the parent component's HTML template using a button, how can I pass the parent component's data (such as a name) to the child component without displaying it in the URL? ...