I have these 2 templates, and the book has a list of language objects.
Model book
import { Language} from "./language";
export class Book {
id: number;
name: string;
language: Array<Language>;
}
Model language
export class Language{
id: number;
name: string;
}
Quando tento criar o objeto livro e adicionar uma linguagem na sua listagem de linguagens, tenho erro de undefined:
myBook: Book();
myLanguage: Language();
hello() {
this.myLanguage = new Language();
this.myLanguage.id = 1;
this.myLanguage.name = "portuguese";
this.myBook = new Book();
this.myBook.id = 1;
this.myBook.name = "one book";
this.myBook.language.push(this.myLanguage); //error - undefined
}
Would you need a different kind of declaration for this listing?
Thank you.