image
フォルダavatar
のすべてのファイル名を読み取ろうとしていますが、エラーが発生しています。Angular4ローカルファイルを読み取る
Cannot find name 'require'.
私はavatar
内のファイルがたくさんあると<images>
要素としてそれらを一覧表示します。それで、なぜ私はフォルダ内のファイル名を取得しようとしたのですか?
私は私のフォルダ構造がある角度4.2.5との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;
}
}
を使用しています:あなたのコードで
-app
---|room
------|profile
---|assets
------|image
----------|avatar
fsはノード組み込みライブラリです。どうしてnodejで角度をつけようとしているのですか? – nadavvadan
それでは、どうやってfuなしでアンギュータのローカルファイルを読むことができますか? – Samy
あなたのフォルダ構造 – Aravind