Loop through all files/images in a folder with Angular

拈花ヽ惹草 提交于 2019-12-01 06:40:24
Radonirina Maminiaina

You can't do that with frontend. What you need to is using your back-end and return file in it.

You are using NodeJs as back-end so can use the fs.readdir or fs.readdirSync methods.

fs.readdir

const testFolder = './images/';
const fs = require('fs');

fs.readdir(testFolder, (err, files) => {
  files.forEach(file => {
    console.log(file); // use those file and return it as a REST API
  });
})

fs.readdirSync

const testFolder = './images/';
const fs = require('fs');

fs.readdirSync(testFolder).forEach(file => {
  console.log(file);
})

Read the full documenation, it may help you to how you can proceed.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!