【问题标题】:How to work with cordova file plugin in ionic 2如何在ionic 2中使用cordova文件插件
【发布时间】:2016-12-15 07:30:00
【问题描述】:

我正在研究 ionic 2。

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

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

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

使用 ionic 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 上遇到错误,我应该怎么做才能解决打字稿中的这些错误。

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

【问题讨论】:

    标签: cordova typescript ionic2


    【解决方案1】:

    永远不要将它存储在文件中,使用离子存储,效果非常好!

    https://ionicframework.com/docs/storage/

    【讨论】:

      猜你喜欢
      • 2016-11-02
      • 1970-01-01
      • 2017-02-05
      • 1970-01-01
      • 1970-01-01
      • 2017-05-23
      • 2017-05-14
      • 1970-01-01
      • 2015-04-08
      相关资源
      最近更新 更多