Currently, I am working with Ionic 2 and trying to integrate the file plugin into my project. I have followed the installation process by using the command
ionic plugin add cordova-file-plugin
, but I am facing difficulties in making it work.
Is there any demo available for working with Ionic 2 that I can refer to? I am looking to save the username and password to a file so that even when the user closes the app, they can still navigate back to the home page if the correct credentials are stored in the file. On the contrary, if the user enters the wrong credentials, it should only show the login page.
Here is a snippet of my code:
import {Component} from '@angular/core';
import {NavController} from 'ionic-angular';
import {File} from 'ionic-native';
@Component({
templateUrl: 'build/pages/home/home.html'
})
export class HomePage {
private userName: any;
private password: any;
constructor(public navCtrl: NavController) {
this.userName = "Admin";
this.password = "Admin123";
}
createFile(dirEntry, fileName, isAppend) {
// Creates a new file or returns the file if it already exists.
dirEntry.getFile(fileName, {create: true, exclusive: false}, function(fileEntry) {
writeFile(fileEntry, null, isAppend);
}, onErrorCreateFile);
}
}
I am encountering errors with
writeFile
andonErrorCreateFile
in TypeScript. Any suggestions on how to resolve these errors?Additionally, I am curious about how I can store and check the username and password in my file. Is there a way to verify if the credentials have been successfully stored?