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}} </h2>
<p>phone.</p>
<button ion-button clear item-right>View</button>
</ion-item>
</ion-list>