samedi 9 mai 2015

Display all images from one directory having a prefix [Angular & Node]

I´m figuering out how to display all images in one folder with AngularJS. Problem is, I just want to get the images having the same specific prefix in their filename. The prefix always ends with a dot, e.g. 5412ec.test.jpg.

How do I display a complete folder of images in Angular? And how do I look for the prefix? I´ve tried displaying the whole folder, like this, but got a 404.

NodeJs

app.get('/uploads/', function (req, res, next){
    fs.readdir('/uploads/', function(err, files){
        if (err) return next (err);
        res.send(files);
    });
});

Angular Controller

$http.get('/uploads/').then(function (files){
    $scope.img = files;
});

Displaying images

<li ng-repeat="x in img">
    <img ng-src="x" width="150" height="100"/>
</li>

Cheers, Wandkleister.

Aucun commentaire:

Enregistrer un commentaire