【发布时间】:2016-11-05 15:03:08
【问题描述】:
尝试设置表单,但由于某种原因,我的 html 中的日期输入未绑定到对象的日期值,尽管使用 [(ngModel)]
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[]
){
}
}
测试输出显示当前“新”日期作为对象的值,但输入没有更新用户对象的日期值或反映该值,这表明双向绑定都不起作用。非常感谢您的帮助。
【问题讨论】:
标签: html angular typescript angular2-forms