如何在离子2中使用cordova文件插件

时间:2016-08-09 09:56:15

标签: cordova typescript ionic2

我正在研究离子2。

http://ionicframework.com/docs/v2/native/file/

https://github.com/apache/cordova-plugin-file#persistent

我已使用此命令ionic plugin add cordova-file-plugin安装了文件插件但我不知道如何使用它。

任何使用离子2的演示,我应该从哪里开始。

我的要求是将用户名和密码保存到文件中,甚至他们关闭应该访问主页的应用程序,因为正确的用户名和密码存储在文件中。

如果用户输入了错误的用户名和密码,它也应该存储在文件中,但是他们应该只看到登录页面。

这是我的代码

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);

    }
}
  

我在writeFileonErrorCreateFile上收到错误,我应该怎么做以解决打字稿中的错误。

     

如何将我的用户名和密码存储到我的文件中如何检查它是否存储或不存储。

1 个答案:

答案 0 :(得分:0)

不要将其存储在文件中,使用离子存储,工作得非常好!

Check