В вашем файле ts:
export class HomePage {
fileValue:string;
constructor(private plt:Platform,private file: File) {}
checkValueExist(){
return (this.fileValue);
}
createFile(){
if(this.checkValueExist()){
this.file.createFile(this.file.dataDirectory,this.fileValue,true).then(xfile=>{
let filePath = xfile.nativeURL.substr(0, xfile.nativeURL.lastIndexOf('/') + 1);
if (this.plt.is('android')) {
this.copyToAppAndroidDir(filePath, xfile.name, this.createFileName(xfile.name));
}else{
this.copyToAppIosDir(filePath, xfile.name, this.createFileName(xfile.name));
}
}).catch(err=>{
alert('File Not Created cause of : '+ JSON.stringify(err));
})
}else{
alert('empty text');
}
}
createFileName(name) {
var newFileName = name + ".txt";
return newFileName;
}
copyToAppAndroidDir(namePath, currentName, newFileName) {
this.file.copyFile(namePath, currentName, this.file.externalDataDirectory, newFileName).then(success => {
alert('done');
}, error => {
console.log('err :', error);
});
}
copyToAppIosDir(namePath, currentName, newFileName) {
this.file.copyFile(namePath, currentName, this.file.dataDirectory, newFileName).then(success => {
alert('done');
}, error => {
console.log('err :', error);
});
//here in the this.file.dataDirectory for ios it may work or could be tempDirectory since in reality i have android device and don't know where ios store its files so you can change when testing on ios and know the directory.
}
}
И в html:
<ion-input type="text" [(ngModel)]="fileValue"></ion-input>
<ion-button color="primary" shape="round" expand="block" (click)="createFile()">Create File</ion-button>