Home > Blockchain >  Angular how to change datetime format in input value attribute
Angular how to change datetime format in input value attribute

Time:01-03

I have input with value of datetime-local and I need to change the format and display the time but it's not working

<div >
    <h5 >Collection Date</h5>
    <input type="text" id="disabledTextInput" disabled 
    [value]="{{ collect_date | date:'dd/MM/yyyy h:mm a' }}">
</div>

It gives me this error Parser Error: Got interpolation ({{}}) where expression was expected

CodePudding user response:

[] and {{}} are never used together.{{}} is for string interpolation only.

Use value as below

[value]="collect_date | date: 'dd/MM/yyyy h:mm a'"

https://stackblitz.com/edit/angular-ivy-tefeqa?file=src/app/app.component.html

CodePudding user response:

when wrapping your directive name with [square brackets] you can not use {{double curly brackets}} for its value,

you can either put it like this:

value="{{ collect_date | date:'dd/MM/yyyy h:mm a' }}"

or like this:

[value]="collect_date | date:'dd/MM/yyyy h:mm a'"

  • Related