Hello there,
I just tested the Keychain-plugin and it works fine, except when my ion-input is empty before the first click on save.
If I write something into the input field and click on save anything works, and if I empty the field after and click on save, I get the alert I want to have.
But like I said, if I press save after open the app, it crashes
my home.ts:
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { Keychain} from "@ionic-native/keychain";
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
public name: string;
public getName: string;
constructor(public navCtrl: NavController, private keychain: Keychain) {
}
saveWithKeychain() {
if (this.name !== '') {
this.keychain.set('login', this.name, true);
} else {
alert('No Name');
}
}
loadWithKeychain() {
this.keychain.get('login', 'Touch it').then(data =>{
this.getName = data;
})
}
}
and my home.html:
<ion-header>
<ion-navbar>
<ion-title>
Ionic Blank
</ion-title>
</ion-navbar>
</ion-header>
<ion-content padding>
<ion-list>
<ion-item>
<ion-label>Name</ion-label>
<ion-input type="text" [(ngModel)]="name"></ion-input>
</ion-item>
<button ion-button (click)="saveWithKeychain()">Save your Name</button>
<button ion-button (click)="loadWithKeychain()">Load the Name</button>
<ion-item>
<p>Get Name: {{getName}}</p>
</ion-item>
</ion-list>
</ion-content>
Thank you in advance