试图设置表单,但出于某种原因,尽管使用了[(ngModel)],但my html中的日期输入没有绑定到对象的日期值
html:
<input type='date' #myDate [(ngModel)]='demoUser.date'/><br>
表单组件:
export class FormComponent {
demoUser = new User(0, '', '', '', '', new Date(), '', 0, [], []);
}
用户类别:
export class User {
constructor (
public id: number,
public email: string,
public password: string,
public firstName: string,
public lastName: string,
public date: Date,
public gender: string,
public weight: number,
public dietRestrictions: string[],
public fitnessGoals: string[]
){
}
}
测试输出将当前"新"日期显示为对象的值,但输入不会更新用户对象的日期值或反映该值,这表明双向绑定都不起作用.非常感谢您的帮助.