1

I have application in Angular 8, I have input type date binded with property Date from object in Angular:

 <input type="date" [(ngModel)]="day.dayValue"  class="form-control" [disabled]="false"/>

And the DayDTO object in TypeScript:

export class DayDTO {
  id: number;
  name: string;
  dayValue: Date;
}

When I set value in this input by hand the property dayValue is set. But when I want to set input type text by assigning:

this.day.dayValue = res.dayValue

when dayValue comes from controller written in .NET Core: dayValue in format T

the input type Date isn't set. When I remove T00:00:00 in string, the input type Date is set


Only works when I remove T00:00:00 without T

1 Answer 1

2

Use the date Pipe in your date input

Like this

"day.dayValue | date: 'yyyy-MM-dd'"

Full code [Edited]

<input
  type="date"
  [(ngModel)]="day.dayValue"
  [ngModel]="day.dayValue | date: 'yyyy-MM-dd'"
  [disabled]="false"
/> />

Notice that I added both [ngModel] and [(ngModel])

You can take this and place it instead of your input and it will work.

Sign up to request clarification or add additional context in comments.

3 Comments

Doesn't work: Parser Error: Cannot have a pipe in an action expression at column 16 in [day.dayValue | date: 'yyyy-MM-dd'=$event]
Thanks, but unfortunatly doesn't work too :(
Hey, sorry for that, here is a link for an example, it worked. Notice that the order of the attributes in the date input is matter.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.