I have the following class FileInfo
that implements IFileInfo
interface.
The class defines an instance member function ext
and a function getExt()
. in my component I have a private method called openTempFolder()
which is basically an http call that return an Array of FileInfo
.
I keep getting a TypeError
that getExt()
is not a function and ext
keeps returning Undefined
upon calling them.
What am I doing wrong here?
I am posting the relevant code,
export class FileInfo implements IFileInfo {
constructor(
public exists: boolean,
public length: number,
public physicalPath: string,
public name: string,
public lastModified: Date,
public isDirectory: boolean,
public ext: () => string,
) {
this.exists = exists;
this.length = length;
this.physicalPath = physicalPath;
this.name = name;
this.lastModified = lastModified;
this.isDirectory = isDirectory;
this.ext = () => {
return this.name.replace(/^.*\./, '');
};
}
getExt() {
return this.name.replace(/^.*\./, '');
}
}
in my component I call this way,
export class FileManagerComponent implements OnInit, OnDestroy {
@ViewChild('fileManager') public fileManager;
public contents: Array<FileInfo> = new Array<FileInfo>();
private unsubscribe: Subject<void> = new Subject();
....
private openTempFolder() {
this.httpService
.getRequest<Array<FileInfo>>('FileManager/OpenTemporaryDirectory/Uploads')
.subscribe((r: HttpResponse<Array<FileInfo>>) => {
this.contents = r.body;
this.contents.forEach(e => {
console.log(e.getExt()); // TypeError
console.log(e.ext()); // Undefined
});
});
}
}