john
john

Reputation: 707

How to set two way binding for a date object?

I'm trying to implement DatePicker to return a Date Value similar to this example in Angular 6

https://stackblitz.com/angular/klxqgnondlx?file=app%2Fapp.component.html

It works great . . . . . . . but it returns a JSON date rather than Date object, so the two way binding with a corresponding date field doesn't work.

I need the date picker to return Date object not JSON

Here is what I tried

   <input class="form-control" type="date" placeholder="yyyy-mm-dd"
     id ="myDate" name="myDate" [(ngModel)]="model.myDate| date:'yyyy-mm-dd'" ngbDatepicker #d="ngbDatepicker"  (ngModelChange)="myDate= $event" > 

But it didn't work

Upvotes: 0

Views: 790

Answers (1)

Dave B
Dave B

Reputation: 69

What is returned is up to the library you are using. You could always use a different library. It might be easiest to just make your model a string (representation as JSON date), and convert it to a Date object when you actually need to use the Date representation.

Upvotes: 1

Related Questions