简体   繁体   English

ionic3:如何连接单选按钮的值以连接到页面

[英]ionic3: How to connect values of radio button to connect to a page

Ionic 3...App contains news page and settings page. Ionic 3 ... App包含新闻页面和设置页面。
The Settings Page has to change the following settings of the app using radio buttons : • The news source the app reads the news from. 设置页面必须使用单选按钮更改应用程序的以下设置:•应用程序从中读取新闻的新闻源。 changes made on this page should be stored when the Save button is pressed. 按下“保存”按钮时,应存储在此页面上所做的更改。 When the Settings Page is open again these changes should be reflected. 再次打开“设置”页面时,这些更改应反映出来。

i am unable to link radio buttons to particular news source 我无法将单选按钮链接到特定新闻来源

If you are not working with some kind of backend you could use Ionic LocalStorage. 如果您不使用某种后端,则可以使用Ionic LocalStorage。 You need to install the Storage plugin for this to work. 您需要安装存储插件才能正常工作。 To do so follow this link . 为此,请点击此链接

In settings.ts you should have something like this. settings.ts您应该有这样的内容。

import { Storage } from '@ionic/storage';

firstOption: String;

export class Settings {
  constructor(private storage: Storage) { }

  ionViewWillEnter() { 
    this.setUpSettings();
  }

  optionSelected(option,value) {
    this.storage.set(option,value);
  }

  setUpSettings() {
    this.storage.get('firstOption').then((res) => {
      this.firstOption = res;
    });
  }
}

Then in settings.html 然后在settings.html

<ion-content>

  <ion-list radio-group [(ngModel)]="firstOption">

    <ion-item>
      <ion-label>BBC</ion-label>
      <ion-radio (ionSelect)="optionSelected('firstOption','bbc')" value="bbc"></ion-radio>
    </ion-item>

    <ion-item>
      <ion-label>CNN</ion-label>
      <ion-radio (ionSelect)="optionSelected('firstOption','cnn')" value="cnn"></ion-radio>
    </ion-item>

  </ion-list>

</ion-content>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM