1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

SQL Lite Storage sometimes return null ionic 3

Discussion in 'Programming/Internet' started by Ahmed Fouad, Sep 12, 2018.

  1. Ahmed Fouad

    Ahmed Fouad Guest

    I’m building an app in multiple languages I’m using SQL Storage lite for keeping the chosen language but sometimes the storage returns null

    <ion-item class="settings-items" no-border ion-item>
    <ion-icon class="img-view" item-start name="ios-globe">
    </ion-icon>
    <ion-label [ngClass]="(this.Platform.isRTL ) ? 'settings-textAr': 'settings-text' ">{{'LANG' | translate}}</ion-label>
    <ion-select mode="ios" [(ngModel)]="lang" item-end (ionChange)="switchLanguage()">
    <ion-option class="options" value="en" [selected]="lang === english">
    English
    </ion-option>
    <ion-option class="options" value="ar" [selected]="lang === arabic">
    العربية
    </ion-option>
    </ion-select>
    </ion-item>


    select lang

    switchLanguage() {
    if (this.lang === 'en') {

    this.translate.use(this.lang)
    this.Platform.setDir('ltr', true)
    this.storage.set('DocLang' , JSON.stringify(this.lang))
    } else {

    this.Platform.setDir('rtl', true)
    this.translate.use(this.lang);
    this.storage.set('DocLang' , JSON.stringify(this.lang))

    }


    getting the language and setting it with the direction

    this.Storage.get('DocLang').then((val) => {
    this.lang = JSON.parse(val)

    console.log(this.lang)
    if (this.lang === 'en') {
    this.TranslateService.use('en');
    this.platform.setDir('ltr', true);

    } else if(this.lang === 'ar'){
    this.TranslateService.use('ar');
    this.platform.setDir('rtl', true);

    }
    });

    Login To add answer/comment
     

Share This Page