I am having this problem for the first time, I think it is because of the promise here and waiting. Anyone know how to fix this? I put the part of the code where the error occurs, the whole class and the error at the bottom.
Part of code with error:
this.languages = await this.languageService.getAll().toPromise()
this.languages.forEach(async (language) => {
this.languageOption = new DropdownOption
this.languageOption.set (
language.getName(),
language.getId()
)
Language class:
export class Language {
private id: number;
private name: string;
private code: string;
private charset: string;
private isDefault: boolean;
private isActive: boolean;
private systemId: number;
public constructor() {
this.id = null;
this.name = '';
this.code = '';
this.charset = '';
this.isDefault = false;
this.isActive = false;
this.systemId = null;
}
public set(
_id: number,
_name: string,
_code: string,
_charset: string,
_isDefault: boolean,
_isActive: boolean,
_systemId: number
) {
this.id = _id;
this.name = _name;
this.code = _code;
this.charset = _charset;
this.isDefault = _isDefault;
this.isActive = _isActive;
this.systemId = _systemId;
}
public getId(): number {
return this.id;
}
public getName(): string {
return this.name;
}
public getCode(): string {
return this.code;
}
public getCharset(): string {
return this.charset;
}
public getIsDefault(): boolean {
return this.isDefault;
}
public getIsActive(): boolean {
return this.isActive;
}
public getSystemId(): number {
return this.systemId;
}
public setId(_id: number): void {
this.id = _id;
}
public setName(_name: string): void {
this.name = _name;
}
public setCode(_code: string): void {
this.code = _code;
}
public setCharset(_charset: string): void {
this.charset = _charset;
}
public setIsDefault(_isDefault: boolean): void {
this.isDefault = _isDefault;
}
public setIsActive(_isActive: boolean): void {
this.isActive = _isActive;
}
public setSystemId(_systemId: number): void {
this.systemId = _systemId
}
}
Error:
Uncaught (in promise): TypeError: language.getName is not a function TypeError: language.getName is not a function
console.log(language)print?languageService.getAll()returns "plain" objects and not the instances ofLanguageclassthis.languages = this.languages.map(lang => new Language(lang))