ubicak
December 24, 2018, 11:03pm
1
I cant use “ids” variable in another function. Alltimes returned as undefined. How i can use this variable. This is so important for me. Because i will use this variable at http requests.
storageGet(){
this.storage.get('favoriteStory').then((val) => {
this.ids = val;
});
}
gokujy
December 25, 2018, 1:22pm
2
Working fine your code…
home.ts
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { Storage } from '@ionic/storage';
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
public ids;
constructor(public navCtrl: NavController, private storage: Storage) {
// set a key/value
storage.set('favoriteStory', 'Anime');
}
storageGet(){
// Or to get a key/value pair
this.storage.get('favoriteStory').then((val) => {
this.ids = val;
console.log(this.ids)
console.log('Your favoriteStory is', val);
});
}
}
home.html
<ion-content padding>
<button ion-button (click)="storageGet()">Favorite Story</button>
</ion-content>
ubicak
December 25, 2018, 5:30pm
3
Yes this code working. But i want use “this.ids” another function. How i can do?