Loading...
Important Notice - Forums is archived

To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Product icon
TUTORIAL

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.

Vaadin-date-picker dynamically set a default date using Angular2

Suma N
5 years ago Aug 10, 2016 10:35am
Teemu Pöntelin
5 years ago Aug 10, 2016 12:00pm

Hi,

I think the problem here is that you are setting the value in an incorrect format, which causes it to be reverted to an empty string.

Please try something like the following. The example uses a ES6/TypeScript template literal, but as you can see the correct format is format is yyyy-mm-dd.

pad(i: number) {
  return i < 10 ? '0' + i : i;
}

ngOnInit() {
  const selectedDate = new Date();
  this.birthday = `${selectedDate.getFullYear()}-${this.pad(selectedDate.getMonth() + 1)}-${this.pad(selectedDate.getDate())}`;
}

 

Suma N
5 years ago Aug 11, 2016 4:10am
Suma N
5 years ago Aug 16, 2016 4:29am