Search code examples
angularionic-frameworkionic-native

Writing a text file in Ionic?


I want to write a text file in Ionic and I've tried many different methods and neither of them works

import { Filesystem, Directory, Encoding } from '@capacitor/filesystem';
writeSecretFile = async () => {
    await Filesystem.writeFile({
      path: 'secrets/text.txt',
      data: "This is a test",
      directory: Directory.Documents,
      encoding: Encoding.UTF8,
    });
  };

In this case, My app wont even start, source

import { FileOpener } from '@ionic-native/file-opener/ngx';
  fun() {
    this.fileOpener
      .open('./filer.pdf', 'application/pdf')
      .then(() => console.log('File is opened'))
      .catch(e => console.log('Error opening file', e));
  }
}

this wont work either Stackbuiltz code All the efforts are highly appreciated


Solution

  • You also have to import the package into your app.module.ts