Hello guys. I’ve been killing myself over this for like few hours already. I have a PHP api that i load JSON data from.
I load this data via http provider and it works perfectly fine.
The issue happens when i want to show all the data from arrays into ion list. I’ve made a classic loop but it only show output of one array object at index for some reason.
Here is my TS file code:
import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { HttpProvider } from '../../providers/http/http';
@IonicPage()
@Component({
selector: 'page-ulice',
templateUrl: 'ulice.html',
providers: [HttpProvider]
})
export class UlicePage {
dbData: any;
loading: any;
constructor(public navCtrl: NavController, public navParams: NavParams, public httpProvider: HttpProvider) {
this.getdata();
}
getdata() {
// this.loading.present();
this.httpProvider.getJsonData().subscribe(
result => {
this.dbData = result;
console.log("Success : " + this.dbData);
},
err => {
console.error("Error : " + err);
},
() => {
// this.loading.dismiss();
console.log('getData completed');
}
);
}
showStreets() {
for (var i = 0; i < this.dbData.length; i++) {
return this.dbData[i].id;
}
}
showNames() {
}
filter() {
}
}
And here is my HTML file:
<ion-header>
<ion-navbar color="myDark">
<ion-title>Ulice</ion-title>
</ion-navbar>
</ion-header>
<ion-content padding>
<ion-list>
<ion-item *ngFor="let item of dbData">
<p (click)='showNames()'>{{showStreets()}}</p>
</ion-item>
</ion-list>
<ion-fab bottom right>
<button ion-fab (click)="filter()" color="myPrimary2">
<ion-icon name="search"></ion-icon>
</button>
</ion-fab>
</ion-content>
Here is what i get as output:
What am i doing wrong?