Hi, i just installed File in my app, version “@ionic-native /file”: “^3.2.1”.
But when I get the error "No provider for File!!
I just followed the documentation.
This is the code.
import { File } from ‘@ionic-native /file’;
constructor(public navCtrl: NavController,
public navParams: NavParams,
public storage: Storage,
public file: File
) { }
lalala() {
this.file.checkDir(this.file.dataDirectory, ‘mydir’).then(_ => console.log(‘Directory exists’)).catch(err => console.log(‘Directory doesnt exist’));
}
Any clue?? Thank you.
Any help about this?
I dont know what can I do, doesnt matter what i try, always says No provider for File!
i use this instead
var file = new File();
and everything works fine.
You have to declare your provider in app.modules.ts
Exactly where did you used that line of code?
You need to upgrade your project to the latest Ionic Native 3.x++
Here’s an example of including Speech Recognition:
Ensure you’ve included File in your providers within app.module.
Hi!, as I said in the post earlier, I’m having problems with every single plugin.
Now its the same with File plugin, and Social Sharing plugin.
I’m following the docs from Ionic 2, but both give me the same error, in both of them. No provider for…
Here is an image with my package.json, i think i have the ionic-native up to date.
Thanks!!
david_bc:
provider
on the constructor of my page
i share part of my code
saveInFile(passed) {
var file = new File();
var date = new Date();
var text = `${this.rpc.username} ${this.tag.connected.id} ${date.toLocaleDateString()} ${passed? 'OK' : 'INCOMPLETE'} \n`;
var dir = file.externalRootDirectory + "bt-prod"
console.log(dir);
file.checkDir(file.externalRootDirectory, "bt-prod").then((res)=>{
if(!res){
file.createDir(file.externalRootDirectory, "bt-prod", false).then(()=>{
console.log("Directory writed");
}).catch((err)=>{
console.error("error creating dir",err);
});
}
});
setTimeout(()=>{
file.checkFile(dir, "bt-prod-" + date.getDate() +"-"+date.getMonth() + ".txt").then((res)=>{
if(!res){
file.createFile(dir, "bt-prod-"+ date +".txt",false).then(()=>{
console.log("file created");
}).catch((err)=>{
console.error("error creating file");
});
}
});
},500);
setTimeout(()=>{
file.writeExistingFile(dir, "bt-prod" + date.getDate() +"-"+date.getMonth() + ".txt", text).then(()=>{
console.log("file writed");
}).catch((err)=>{
console.error("error writing file",err);
});
},1000)
}
Did you add File to providers in app.module?
Since the introduction of Ionic-Native 3.2.1, the plugins have to be declared as providers, see documentation:
1 Like
Yes, I already did it, its declared in the providers list.
Ok, sorry to hear that. I checked what I’ve got, I use version 3.2.2 but I don’t think that’s the difference.
Otherwise, just in case, I really just do that:
app.module.ts:
import {File} from '@ionic-native/file';
....
providers: [
...
File,
....
using it:
import {File, DirectoryEntry} from '@ionic-native/file';
....
constructor(private file: File) {
}
...
let fs: string = cordova.file.cacheDirectory;
...
this.file.resolveDirectoryUrl(fs).then((rootDir: DirectoryEntry) => {
console.log('Coolio');
}, (errRoot: any) => {
console.log('Less coolio');
});
works for me (of course not in the browser).
3 Likes
I’ve been stalking this thread since yesterday, finally got something useful out of it. Thanks!
1 Like
I already had everything you said, but I deleted the lines, and wrote it again, now its working, dont know what was different exactly, but now its working.
Thank you all!
1 Like
david_bc:
said
that’s is the correct way
import { File } from ‘@ionic-native /file’;
constructor(public navCtrl: NavController,
public navParams: NavParams,
public storage: Storage,
public file: File
) { }
lalala() {
this.file.checkDir(this.file.dataDirectory, ‘mydir’).then(_ => console.log(‘Directory exists’)).catch(err => console.log(‘Directory doesnt exist’));
}
Solo tienen que leer la documentación y se ahorrarán dolores de cabeza.
[](http://commitizen.github.io/cz-cli/) 
# Awesome Cordova Plugins
Awesome Cordova Plugins is a curated set of wrappers for Cordova plugins that make adding any native functionality you need to your [Ionic](https://ionicframework.com/) mobile app easy.
Awesome Cordova Plugins wraps plugin callbacks in a Promise or Observable, providing a common interface for all plugins and making it easy to use plugins with Angular change detection.
To learn more about the reasons why Ionic Native was renamed to Awesome Cordova Plugins, read the official [Ionic blog](https://ionicframework.com/blog/a-new-chapter-for-ionic-native/) post by Max Lyncht.
## Capacitor Support
In addition to Cordova, Awesome Cordova Plugins also works with [Capacitor](https://capacitorjs.com), Ionic's official native runtime. Basic usage below. For complete details, [see the Capacitor documentation](https://capacitorjs.com/docs/v2/cordova/using-cordova-plugins).
## Installation
Run following command to install Awesome Cordova Plugins in your project.
```bash
npm install @awesome-cordova-plugins/core --save
This file has been truncated. show original
mosta2
March 1, 2018, 1:51pm
19
Put the provider in the @component declaration:
@Component({
selector: 'xxx',
templateUrl: 'xxx',
providers: [File]
})
1 Like