Boolean for loading different data

#1

l am working on ionic 4 project. My project is getting data json from url content flights schedules . Everything is okay , but l want to use button boolean when users click on button show to users the flights schedules for yesterday . l don`t want to create another page for holding flights schedules for yesterday l want used in same page and same code . l did like this but when l click on button he is not load any information shows for flights schedules yesterday

  Loadearlierflights : boolean = true;

      async getData() {


        const loading = await this.loadingController.create({
          message: 'Loading'
        });
        await loading.present();

          /// flights details for today ///

        if (this.Loadearlierflights=true) {
          this.http.get('xxxxxxx/airport.json?code=bsr', {}, {})
          .then(data => {

            this.test = JSON.parse(data.data);
            const parsed = JSON.parse(data.data);
            this.items = parsed.pluginData.schedule.arrivals.data;
            loading.dismiss()


            console.log(this.items)

          }), err=>{
            this.test =err
            loading.dismiss()
          } 

                   /// flights details for yesterday ///

        }else if (this.Loadearlierflights=false) {
          this.http.get('xxxxxxxx/airport.json?code=bsr&page=-1', {}, {})
          .then(data => {

            this.test = JSON.parse(data.data);
            const parsed = JSON.parse(data.data);
            this.items = parsed.pluginData.schedule.arrivals.data;
            loading.dismiss()


            console.log(this.items)


          }), err=>{
            this.test =err
            loading.dismiss()
          }

        }

html

<ion-button shape="round" (click)="getData()">load earlier flights</ion-button>

any ideas please ?

#2

Hello,
maybe an easy way is to add a parameter to your method like getdata(‘yesterday’) and check it.

Best regards, anna-liebt

#3

can l you give example please on my code ?

thank you

#4

https://stackblitz.com/edit/ionic-5fn3jbllo,
look here https://stackblitz.com/edit/ionic-5fn3jb

Best regards, anna-liebt

Ps: forgot boolean, but the principle is the same.