【发布时间】:2020-06-28 18:54:15
【问题描述】:
在我的 Angular 应用程序中,我想列出资产文件夹中的所有文件名。
所以我想使用这个 npm 库:list-files-in-dir
https://www.npmjs.com/package/list-files-in-dir
所以我在我的 Angular 应用程序中提供了这项服务:
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import {listFiles} from 'list-files-in-dir';
@Injectable()
export class ConfigService {
files: any;
constructor(private http: HttpClient) { }
getFilesFromFolder(){
listFiles('assets/')
.then(files => {
// do what ever you want with the file paths
this.files = files
console.log(this.files)
}
}
}
但是当调用它时我得到这个错误:
错误错误:未捕获(承诺):错误:错误:ENOENT:没有这样的文件 或目录。, '/assets' 错误
我为此做了一个stackblitz sn-p:
https://stackblitz.com/edit/angular-read-jsonfile-data
建议?
【问题讨论】:
-
您希望能够从您的 Angular 应用程序中读取什么文件系统?我假设这是在浏览器中运行的普通 Angular 应用程序?
-
在浏览器中运行时无法访问文件系统。
-
任何简单的替代方案?
标签: javascript node.js angular typescript