After done the api calling. In my db I have set of json object values. The structure is look like this :
{
"status": 1,
"message": "List Successfully fetched",
"CatgeoryList": [
{
"CatID": "10"
},
{
"CatID": "30"
},
{
"CatID": "0"
}]
}
I have done api calling. And i get the status == 1
. And i can print all the object values under in CatgeoryList
. But i want to print all the catID
UNDER IN CatgeoryList
. i was not able to get.
here my code :
this.authService.categ(this.loginData).then((result) => {
this.loading.dismiss();
this.data = result;
if(this.data.status == 1)
{
this.Catdata = this.data.CatgeoryList;
console.log(this.Catdata); // i am getting all data
this.Catdatanames = this.Catdata.CatID; // not working
console.log(this.Catdata.CatID); // not working
}
}
I want to get the catID
underCatgeoryList
.
Update :
Update of home.html:
<div class="item item-body no-padding" style="border-width: 0px !important;">
<div class="row no-padding" *ngFor="let data of Catdata;let i = index" (click)="opndetailpage()">
<ng-container *ngIf=" i % 2 === 0">
<div class="col col-50 custom-design2" style="background: url(url) no-repeat center;background-size: cover;">
<div class="custom-design1"><span class="grid-title">{{Catdata[i].CategoryName}}</span></div>
</div>
<div class="col col-50 custom-design2" style="background: url(url) no-repeat center;background-size: cover;">
<div class="custom-design1"><span class="grid-title">{{Catdata[i+1].CategoryName}}</span></div>
</div>
</ng-container>
</div>
</div>
home.ts
constructor(
public alertCtrl: AlertController,
public app: App,
public loadingCtrl: LoadingController,
public modalCtrl: ModalController,
public navCtrl: NavController,
public toastCtrl: ToastController,
public confData: ConferenceData,
public user: UserData,
public http:Http,
public authService: AuthService
) {
this.showLoader();
this.authService.categ(this.loginData).then((result) => {
this.loading.dismiss();
this.data = result;
if(this.data.status == 1)
{
this.Catdata = this.data.CatgeoryList;
for(let i=0; i<this.Catdata.length; i++) {
console.log(this.Catdata[i].CategoryName);
}
}
else if(this.data.status == 0) {
let alert = this.alertCtrl.create({
title: 'Error',
subTitle: 'Please Enter Valid Username & Password',
buttons: ['OK']
});
alert.present();
}
}, (err) => {
this.loading.dismiss();
});
}
My takeexam.html
<ion-buttons>
<button (click)="canceltap()" style="font-size: 15px;text-transform: none;" ion-button>Cancel
</button>
</ion-buttons>
my takeexam.ts
canceltap() {
// this.navCtrl.pop();
console.log("pop tap");
this.navCtrl.setRoot(TabsPage); .// this is my home page
}
so when i press cancel button in takeexam.html
its going to tabp[age.html ( home page). But in that no data are showing. I just tried with hard code some value in my home page. That time when i press cancel button its showing all data.
so i found the problem is in shoing the data in ionviewdidload or some other. i tried.ionViewDidEnter
ionDidLoad
. but nothing works
Since
this.data.CatgeoryList
is an array, you'll need to use a loop to do something with each itemAnd if you want to show it in the view, you can use ngFor like this
UPDATE
Update the view
You can add a new method on the component code
And in the second page, in the constructor, get the data by using NavParams