How to perform a switch statement on a click event


#1

Hi, I’m completely new to Ionic and have got stuck at the switch statement with a button.
What I want to happen is to save a selection from a radio group on a settings page and then launch a page based on that selection from a button click on the home page.
The app takes a news feed from 3 different sources and the user can select which one through a radio group on the settings page.
At the moment I have 3 different buttons set up but I want to have one only and then the user can choose which page loads when they click the button.

launchNews(){
    this.navCtrl.push(NewsPage);
  }

  launchSport(){
    this.navCtrl.push(BbcsportPage);
  }

  launchGeographic(){
    this.navCtrl.push(GeographicPage);
  }


I want to put the above code in a switch statement but each time I get an error so any help at all would be greatly appreciated

The radio group comes from the SettingsPage and is coded like this

<ion-list radio-group [(ngModel)]="newsSources">
        
          <ion-list-header>
            Sources
          </ion-list-header>
        
          <ion-item>
            <ion-label>Reuters</ion-label>
            <ion-radio value="Reuters1"></ion-radio>
          </ion-item>
        
          <ion-item>
            <ion-label>National Geographic</ion-label>
            <ion-radio value="National Geographic1"></ion-radio>
          </ion-item>

          <ion-item>
              <ion-label>BBC Sport</ion-label>
              <ion-radio value="BBC Sport1"></ion-radio>
            </ion-item>
    </ion-list>

#2

Hello,
maybe you can use @ViewChild to get a reference to a radio.

Or maybe use @ViewChgildren to get reference to all radios.

At the lifecyle ngAfterViewInit() or later is the reference avialable and can used in whatever.you have the reference and could use it

https://www.concretepage.com/angular-2/angular-2-viewchild-example or any other tutorial

Maybe you can bind a property and watch if it changes.

Or maybe…

Best regards, anna-liebt.