我正在使用Ionic 4,并且尝试将导出字符串保存为CSV文件,将其保存到dataDirectory(iOS),然后打开此文件。
import { File } from '@ionic-native/file/ngx';
import { DocumentViewer, DocumentViewerOptions } from '@ionic-native/document-viewer/ngx';
const options: DocumentViewerOptions = {
title: 'My CSV'
};
const data = 'Foo,Bar';
constructor(private file: File,
private documentViewer: DocumentViewer){}
exportCsvFile() {
this.file.writeFile(this.file.dataDirectory,
'test.csv',
data,
{replace: true})
.then((res) =>
this.documentViewer.viewDocument(this.file.dataDirectory + 'test.csv',
'text/plain', options);)
.catch(err => console.log(err));
}
调试时,可以看到文件创建成功。但是documentViewer
不显示任何内容。