[英]Angular6 get all filenames from folder
I'm trying to make a simple Picture Gallery and I want to place all the pictures inside a Folder (./assets/). 我正在尝试制作一个简单的图片库,我想将所有图片放在文件夹(./assets/)中。
Now I created a PictureService which should load all Pictures (well his names to be precise) in an Array so that I can iterate over the array and display them. 现在,我创建了一个PictureService,它将所有图片(准确地说是他的名字)加载到一个Array中,以便我可以遍历该数组并显示它们。
But how do I grep the FileNames? 但是我如何grep文件名? I did something similar with nodejs and liquid once where I simply called a bash job to return the names to me but that doesn't seem clean nor possible here. 我曾经用nodejs和liquid做过类似的事情,在这里我只是简单地调用了一个bash作业来将名称返回给我,但这在这里似乎也不干净。
I really want to hold it clean and simple and don't want to build an extra API for this, to be honest. 老实说,我真的很想保持它的简洁明了,也不想为此增加额外的API。
And I don't want to manual input all these filenames into a JSON or the array either... 而且我也不想手动将所有这些文件名输入到JSON或数组中...
Is there any smart way of doing it? 有什么聪明的方法吗?
thanks a lot! 非常感谢!
我认为您的图片响应API应该像这样的json- { name: 'image1-name', path: 'image1-url' }, {name: 'image2-name', path:'image2-url' }
并尝试使用observable并订阅使用此json API。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.