本地存储无法保存价值

时间:2019-03-02 10:31:29

标签: angular local-storage ionic4

我想从Ionic 4 Modal返回数据,将选中的单选按钮存储在本地存储中。当我单击任意单选按钮以更改初始值并重新加载页面时,我获得了相同的值而不保存在本地存储中

export class Tab1Page {
    weather:any;
    cities = 'Muscat'

    constructor(private https: HttpClient,public popoverController: PopoverController
      ,public nav : NavController,public modalController: ModalController,
      private storage: Storage ) {
        this.test()
    }

    async test (){
        this.https.get('weather/'+this.cities+'.json')
      .subscribe(data => {
            this.weather = data
        })



    }


    async openUserModal() {

        const modal = await this.modalController.create({
            component: PopoverstationsPage,
        });

        await modal.present();
        modal.onDidDismiss().then((r) => {

            console.log("the result:", r , 'test'+ this.cities);
            this.cities = r.data.result

            this.test()
            this.storage.set('cities',this.cities)

            this.storage.get('cities',this.cities).then((val) => {
                console.log('Your city is', val);
            });     

        });

    } 

0 个答案:

没有答案