Typescript 角度模型
我有这个型号Typescript 角度模型,typescript,angular4-forms,Typescript,Angular4 Forms,我有这个型号 export class model{ Id: string; Name: string; home: Home[]; } export class Home{ street: string; country: string; CP: string; } 问题是如何在父模型中使用model Home的值,以及如何在表单中使用这些值来插入新寄存器,例如: <form> <input type="text" ([ngModel])="mo
export class model{
Id: string;
Name: string;
home: Home[];
}
export class Home{
street: string;
country: string;
CP: string;
}
问题是如何在父模型中使用model Home的值,以及如何在表单中使用这些值来插入新寄存器,例如:
<form>
<input type="text" ([ngModel])="model.id">
<input type="text" ([ngModel])="model.Name">
<input type="text" ([ngModel])="model.Home.CP"><!--How to implements the values of home to insert a value in the BD-->
</form>
谢谢胡安·佩雷斯
要在model
类中使用Home[]
数组,需要在model
类构造函数中实例化数组。然后,当将数据绑定到model
类的home
属性时,必须使用home
数组中的索引。可能的代码如下所示
<input type="text" ([ngModel])="model.home[index].CP">
export class model{
Id: string;
Name: string;
home: Home[];
model() {
home = new Array(3).fill(new Home());
}
}
export class Home{
street: string;
country: string;
CP: string;
Home() {
street = "";
country = "";
CP = "";
}
}
什么是父模块?大小写也很重要,如果要访问数组中的项,则需要使用数组索引器或循环访问它并多次访问。可能重复