How to bind the data,already object ,need to convert to array?

hi guys,i am new . and i am trying to bind data,got a problem ,as below. anyone can help? thank you

car.ts

export class CarPage {

carsList = ;
// carsList :any;
constructor(
public navCtrl: NavController,
public RideData: RideService
) { }

ionViewDidLoad() {
console.log(‘Hello CarPage Page’);
// console.log(Config.EndPoint);
this.AllCarsList();

}

AllCarsList() {

this.carsList= this.RideData.loadAllCar();
console.log(11111111111111); ;
console.log(this.RideData.loadAllCar());
// console.log(this.carsList);
console.log(22222222222222);
}
}

providers

@Injectable()
export class RideService {
cars: any;
passengers:any;
constructor(public http: Http) {
console.log(‘Hello RideService Provider’);
this.loadAllCar();
}

loadAllCar() {
if (this.cars) {
// already loaded data
return Promise.resolve(this.cars);
}
// We’re using Angular HTTP provider to request the data,
// then on the response, it’ll map the JSON data to a parsed JS object.
// Next, we process the data and resolve the promise with the new data.
return new Promise(resolve => {
this.http.get(Config.EndPoint+"/FreeRide/GetFreeRideByCar").map(res => res.json()).subscribe(data => {
// this.data=data;
console.log(data);
console.log("-------------------------------");
this.cars = data;
resolve(this.cars);
console.log(this.cars);
});
});
}

<ion-list>
    <ion-item *ngFor="let car of carsList">
        <ion-avatar item-left>
            <img src="assets/test/avatar-ts-woody.png">
        </ion-avatar>
        <h2>{{car.Departure}}--{{car.Destination}} &nbsp; &nbsp; </h2>
   
        <p>phone.</p>
        <button ion-button clear item-right>View</button>
    </ion-item>
</ion-list>

Sry but your Question is a bit hard to understand. Not well formulated.
If I understand you right it could maybe lookmlike this:

this.RideData.loadAllCar().then(data => { 
    this.carsList = data;
});

But maybe you need to acces your array like "data.value"
I don’t know how you pass the data from that service.

I Hope it helps you.

:coffee: u r right.@ MarvinS.the data shows. then() function is so miracle.
thank you very much.

1 Like

I’m glad to help you :slight_smile: