Foreach Ionic 3

I have the following code but I need to know how to make a foreach at the time of subscribing to data that I bring from my web service,

Productos_cargar()
{

let url = URL_SERVICIOS + 'productos';
this.http.get( url )
          .map( resp=> resp.json() )
          .subscribe( data =>{
            

          

           this.por_categoria = data;
          // console.log(this.por_categoria);
          });

}

You need to specify the response data type of data is an array, like:
.subscribe((data: any[]) => { ...
Then use foreach:
data.foreach((item) => { ...

Your data has to be an array to prevent errors though

1 Like