I try to read all file names in my image
folder avatar
but getting the error.
Cannot find name 'require'.
I have a lot of files in avatar
and want list them as <images>
elements. Thats why I tried to get the file-names in the folder .
I'm using Angular 4.2.5 and Webpack
import { Component, Input } from '@angular/core';
var filesystem = require('fs')
const AVATAR_PATH = '../assets/img/avatar'
@Component({
selector: 'profile',
templateUrl: 'profile.component.html',
styleUrls: ['profile.component.scss']
})
export class ProfileComponent {
path = AVATAR_PATH;
constructor() {
console.log(this.getFileNames(AVATAR_PATH));
}
getFileNames(dir)
{
let results =[];
filesystem.readdir(dir).forEach(function(file) {
file = dir+'/'+file;
results.push(file);
});
return results;
}
}
My folder structure is:
-app
---|room
------|profile
---|assets
------|image
----------|avatar