Autoincrement id in angular

0

I have this line in angular, what I want to do is that the id self increases depending on how many images it consumes, I'm clear I'm consuming a service that is being exposed in json

<img id="slide-img-" class="img-item2" src="{{ Our.url }}" alt="{{ Our.alt }}">

example

slide-img-1
slide-img-2
slide-img-3
    
asked by Daniel Salinas 25.08.2018 в 01:03
source

1 answer

0

If you are receiving the data in Json, I recommend that you save it in an array.

   this._apiService.getImagenes().subscribe(data=> {
      for (let i in data) {
        this.lista.push((data[i]));
      }
    }

Once you have the full arrangement you can iterate over this data from your html, and to show an incremental id you can use a variable of type index :

<tr *ngFor="let item of lista; let id = index">


<th>{{id+1}}</th>

The id that will increase with each interaction. One is added because it starts at zero. I hope it serves you, luck!

    
answered by 25.08.2018 / 01:23
source