How to load image in angular 5?

0

<div *ngFor="let datos of archivo" class="card" style="width: 20rem;">
<img class="card-img-top" src="?????" alt="Card image cap">
<div class="card-body">
<h5 class="card-title">{{datos.titulo}}</h5>
<p class="card-text">{{datos.descripcion}}</p>

</div>
</div>

In my database I have a record with the name magazine.png and in the /asset/img/revista.png folder I have the image that I would have to put inside the src loop ????

    
asked by ortiga 26.02.2018 в 19:04
source

1 answer

3

You can fix it in the following way:

<div *ngFor="let datos of archivo" class="card" style="width: 20rem;">
  <img class="card-img-top" [src]="'/asset/img/' + datos.imageName" alt="Card image cap">
  <div class="card-body">
    <h5 class="card-title">{{datos.titulo}}</h5>
    <p class="card-text">{{datos.descripcion}}</p>
  </div>
</div>

What you do here is put the base path '/asset/img/' plus the name of the image corresponding to that item.

  

You can also use String Interpolation (the {{ }} ), but it is less recommended.

    
answered by 26.02.2018 / 19:17
source