Quantcast
Channel: Ionic Forum - Latest posts
Viewing all articles
Browse latest Browse all 230108

IONIC 4 - Cordova file plugin

$
0
0

Hello!
I’m currently trying an app on ionic 4 and i need to use the file plugin (https://ionicframework.com/docs/native/file/).

Here’s what i made:

  • Installed the required packages with ionic cordova plugin add cordova-plugin-file && npm install @ionic-native/file
  • On my class i put the following:
import { Injectable } from '@angular/core';
import { File } from '@ionic-native/file';

@Injectable({
  providedIn: 'root'
})
export class BaseModelService {
  constructor(private file: File) { }

  save(){
      return this.file.writeFile(this.file.dataDirectory, 'hello.json', JSON.stringify({test:'value'}), {replace:true})

  }
}

In my page class i after some logic i simply call

basemodelservice.save();

And i get the error

ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'writeFile' of undefined

What am i doing wrong? Thank you!


Viewing all articles
Browse latest Browse all 230108

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>