【问题标题】:Ionic 3 File Plugin doesn't workIonic 3 文件插件不起作用
【发布时间】:2018-02-15 09:23:39
【问题描述】:

我想将 JSON 数据保存到文件中。

我尝试关注usage guide for file storage 导致以下代码:

import { File } from '@ionic-native/file';

this.file.writeFile("data/", "Kategorien2.json", JSON.stringify(data));

尝试运行此代码时,我收到以下错误:

Can't resolve all parameters for File: (?, ?).

我能做什么?

【问题讨论】:

  • 您是否在模块中添加了 File 作为提供程序?
  • 你在 app.module.ts 中导入了这个
  • 我添加了提供者:[ StatusBar, SplashScreen, SocialSharing, File, {provide: ErrorHandler, useClass: IonicErrorHandler} ]

标签: javascript json angular file ionic-framework


【解决方案1】:

显示错误是因为您没有为 writeFile 方法添加 options 参数。将此代码用于您的目的 =>

import { File } from '@ionic-native/file';
this.file.writeFile("data/", "Kategorien2.json", JSON.stringify(data), {replace : true});

这里我使用了writeFile的replace选项,true表示会替换文件,false表示不会替换文件。

【讨论】:

  • 没有改变任何东西。同样的错误。我的想法(PHPStorm)说“writeFile”是一个“未解析的函数或方法”,对于导入“@ionic-native”“无法解析目录”,但它是存在的
  • 我建议使用 VSCode 进行开发,我使用过 sublime、atom 和 webStrorm,但 VSCode 是最好的。
猜你喜欢
  • 1970-01-01
  • 2018-04-10
  • 2020-12-26
  • 2018-02-19
  • 1970-01-01
  • 2018-05-13
  • 2018-09-10
  • 2019-01-08
  • 1970-01-01
相关资源
最近更新 更多