Home > front end >  Default Input value for datetime-local
Default Input value for datetime-local

Time:01-03

I have a fairly simple date time picker in angular, similar to docs https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/datetime-local

<input type="datetime-local" value="2017-06-01T08:30">

This works fine if I want a fixed hardcoded date. But I want the default value to be a variable, so i can use current date and time. I tried using value="someVar" where someVar = "2017-06-01T08:30", but the value is not read. So it looks like hardcoded date is working, stored date is not. Suggestions? Thanks!

edit: I can't share the ts code, but I have this for the date var

export class someComp { someVar: string = "2017-06-01T08:30"

etc...

}

CodePudding user response:

If you just need to send the 'someVar' to input, use [value]="someVar".

If you want to have 'someVar' potentially changable by some logic later (in ts) use value="{{someVar}}".

  • Related