Я пытался показать массив объектов.
Вот так я получаю в своем компоненте
getFiles(){
this.fileService.getFileList().subscribe(res => {
this.files = res;
console.log(this.files);
})
}
В моем сервисе
getFileList() {
return this.http.get(`http://localhost:4001/files`)
}
вывод из this.files:
> {secret: Array(2)} secret: Array(2) 0: files: (2) ["file1.pdf",
> "file2.pdf"]
> __proto__: Object 1: {pass: "88VpGQAtNB"} length: 2
> __proto__: Array(0)
> __proto__: Object
JSON .stringify дает мне вывод
stringify gave me {"secret":[{"files":["46544556_2.pdf","org_46544556_2.pdf"]},{"pass":"hoc1WpNj63"}]}
Как я могу перебрать этот массив объектов?
<li *ngFor="let file of files" >
{{file}}
</li
Это дает мне ошибку:
Ошибка: Ошибка: не удается найти другой объект поддержки [[объект]] типа «объект». NgFor поддерживает только привязку к итерируемым объектам, таким как массивы.
Мой бэкэнд есть
app.get('/files', function (req, res) {
let folder = app.get('filePath');
const filesInDir = fs.readdirSync(folder, {
withFileTypes: true
})
.filter(item => !item.isDirectory())
.map(item => item.name)
res.send({
secret: [{ files: filesInDir }, { pass: password }],
})
return console.log('files from tmp dir: ' + filesInDir)
});