How to implement Primeng Photo Gallery?

Asked

Viewed 238 times

1

Personal greeting,

I’m trying to implement an image gallery as you can see in the Primeng demo template below;

Gallery

However I am having difficulty due to lack of experience, please my goal and implement this library.

This is the information is in my database

inserir a descrição da imagem aqui

When I load the page it can already load the list of objects as you can see in the picture below;

inserir a descrição da imagem aqui

This is the class of the component;

import { environment } from './../../../environments/environment';
import { EventoService } from './../../core/evento.service';
import { Evento } from './../../models/evento';
import { Component, OnInit } from '@angular/core';

@Component({
  selector: 'app-evento',
  templateUrl: './evento.component.html',
  styleUrls: ['./evento.component.css']
})
export class EventoComponent implements OnInit {

  public title: string;
  public eventos: Evento[];
  public url;

  constructor(
    private _eventoService: EventoService,
  ) {
      this.title = 'Fotos de Eventos';
      this.url = environment.url;
  }

  ngOnInit() {
    this.getEventos();
  }


  getEventos() {
    this._eventoService.getEventos().subscribe(
      response => {
        if (!response.eventos) {

        } else {
          this.eventos = response.eventos;
        }
      },
      error => {
        console.log(<any>error);
      }
    );
  }


}

The problem and does not have much information in the documentation.

THAT WAS MY ATTEMPT;

My HTML;

<div class="col-lg-12">
    <h1>{{title}}</h1>

       <form >
          <p-galleria [images]="eventos" panelWidth="500" panelHeight="313" [showCaption]="true"></p-galleria>
      </form>


</div>

On screen it looked like this;

inserir a descrição da imagem aqui

The slides are passing blank, no images appear, the problem is I’m not able to assemble the logic.

This is my interface.

export class Evento {
    constructor (
        public _id: string,
        public name: string,
        public description: string,
        public year: number,
        public image: string,
        public user: string
     ) {}
}

If I assemble like this the images will appear, but it is not as in the implementation of the Primeng library;

<div class="col-lg-12" [@fadeIn]>
    <h1>{{title}}</h1>

  <div class="col-lg-3" *ngFor="let evento of eventos">
    <div class="thumbnail">
      <div class="animal-image-mask">
        <img src="{{ url + 'get-image-evento/' + evento.image }}" alt="{{evento.name}}" *ngIf="evento.image">
        <img src="http://via.placeholder.com/270x200" alt="{{evento.name}}" *ngIf="!evento.image">
       </div>

    </div>
  </div>

</div>

I did as I suggested;

inserir a descrição da imagem aqui

I put it like this;

getEventos() {
    this._eventoService.getEventos().subscribe(
      response => {
        if (!response.eventos) {

        } else {
          this.eventos = response.eventos.map(evento => {
            return {
              source: evento.image,
              alt: evento.description,
              title: evento.name
             }
           });
        }
      },
      error => {
        console.log(<any>error);
      }
    );
  }
  • has how Voce post your html and how and this your event interface?

  • @Eduardovargas just updated my post could please take a look to get help me.

  • I did another update.

1 answer

2


Try mapping to the interface it uses in the documentation.

else {
      this.eventos = response.eventos.map(evento=>{
       return {
         source:  this.url + 'get-image-evento/' + evento.image ,
         alt: evento.description,
         title: evento.name
        }
      });
}
  • 1

    The interface was already mapped, but shows the same error as before.

  • 1

    I’m sorry, you took most of the stuff, but the image didn’t show up

  • 1

    i updated the post, could take a look is missing little.

  • 1

    i saw in your html that event.image is not the full url I tried to edit there but it is only put a url that makes sense.

  • opa sorry I just saw now, I’ll test

  • hahahaha worked out thank you very much. :)

  • I would just need one more help, but if not possible I will understand, my images are 4608 x 3072 is a very high resolution, I could take my 500 images and resize them one by one in Photoshop, but it would be a very large rework, will be that in this implementation has some configuration to resize the images automatically ?

  • 2

    I would use some site to calculate the ratio of the image type https://andrew.hedges.name/experiments/aspect_ratio/ and I would calculate the width a and height of the component for something that looks cool in this ratio.

Show 3 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.