Odubuc Odubuc - 1 year ago 112
TypeScript Question

NativeScript - TimePicker Cannot get user modified value

I am unable to get the user modified value of a TimePicker. All I'm getting is the original value that I set in the control.

Here is my component template:

<TabView [(ngModel)]="tabSelectedIndex" selectedColor="#FF0000" style="height:90%">
<StackLayout *tabItem="{title: 'Time'}">
<TimePicker #timePicker [(ngModel)]='model.time'></TimePicker>
<StackLayout *tabItem="{title: 'Date'}">
<DatePicker #datePicker [(ngModel)]='model.date'></DatePicker>
<button text="Done" (tap)="onDoneTap()"></button>

And my component code:

export class DateTimePickerComponent
public mDate: Date;
public tabSelectedIndex: number;
public model: any;

this.mDate = new Date();
this.model = {
date: new Date(2014, 5, 13, 2, 24),
time: new Date(2014, 5, 13, 2, 24)

private onDoneTap()



To build this I used the Docs:

  • DatePicker - date property

  • TimePicker - time property

In This example the DatePicker works perfectly, it initialise at 2014-05-13 and when I change it, I get the modified value in the console. So am I doing something wrong with the TimePicker ?

Note: I also tried to read the hour and minute property using the ID without success. Always the same initial value (2:24)

@ViewChild("timePicker") timePicker: ElementRef;
let datePickerView = <TimePicker>this.timePicker.nativeElement;
console.log(datePickerView.hour); // 2
console.log(datePickerView.minute) // 24

Answer Source

For anyone who might fall here:

A bug was opened on Github for this issue. [see here].

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download