我无法获取 TimePicker 的用户修改值。我得到的只是我在控件中设置的原始值。
这是我的组件模板:
<TabView [(ngModel)]="tabSelectedIndex" selectedColor="#FF0000" style="height:90%">
<StackLayout *tabItem="{title: 'Time'}">
<TimePicker #timePicker [(ngModel)]='model.time'></TimePicker>
</StackLayout>
<StackLayout *tabItem="{title: 'Date'}">
<DatePicker #datePicker [(ngModel)]='model.date'></DatePicker>
</StackLayout>
</TabView>
<button text="Done" (tap)="onDoneTap()"></button>
还有我的组件代码:
export class DateTimePickerComponent
{
public mDate: Date;
public tabSelectedIndex: number;
public model: any;
constructor()
{
this.mDate = new Date();
this.model = {
date: new Date(2014, 5, 13, 2, 24),
time: new Date(2014, 5, 13, 2, 24)
};
}
private onDoneTap()
{
this.mDate.setMinutes(this.model.time.getMinutes());
this.mDate.setHours(this.model.time.getHours());
this.mDate.setDate(this.model.date.getDate());
this.mDate.setMonth(this.model.date.getMonth());
this.mDate.setFullYear(this.model.date.getFullYear());
console.log(this.mDate);
}
}
为了构建它,我使用了Docs:
- DatePicker - 日期属性
- TimePicker - 时间属性
在此示例中,DatePicker 完美运行,它在 2014-05-13 初始化,当我更改它时,我会在控制台中获得修改后的值。那么我在 TimePicker 上做错了吗?
注意:我还尝试使用 ID 读取小时和分钟属性,但没有成功。始终相同的初始值 (2:24)
@ViewChild("timePicker") timePicker: ElementRef;
let datePickerView = <TimePicker>this.timePicker.nativeElement;
console.log(datePickerView.hour); // 2
console.log(datePickerView.minute) // 24