Loop through all files/images in a folder with Angular

后端 未结 1 600
时光取名叫无心
时光取名叫无心 2021-01-05 19:13

I have an app with some products and each product has a gallery with a different amount of images. Each of the images has a name that is completely random / no correlation w

相关标签:
1条回答
  • 2021-01-05 19:50

    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.

    0 讨论(0)
提交回复
热议问题