How to change date format in datepicker Angular ngx-bootstrap inside form

Using ngx-bootstrap Datepicker in an Angular 4 app,

I know that usually you can specify the date format as follows:

<input id="from" name="from"
       bsDatepicker [(bsValue)]="myModel"
       value="{{ myModel | date:'yyyy-MM-dd'}}">

but this time I ended up in an Angular form with a template, so my input is not bound to a type variable myModelin the above example, but it is just bound to the form:

<input id="from" name="from"
       bsDatepicker ngModel>

so how can i specify the date format in this case?

Edit : it looks like you can create a new variable newVarinside the component and then bind it to [(bsValue)]="newVar":

<input id="from" name="from"
       bsDatepicker ngModel
       [(bsValue)]="newVar"
       value="{{ newVar | date:'yyyy-MM-dd' }}">

However, I am wondering if there is a better solution.

+6
source share
4

[(bsValue)] bsDatepicker,

,

[(bsValue)]="newVar" value="{{ newVar | date:'yyyy-MM-dd' }}"

bsDatepicker , :

<input name="from" bsDatepicker [(ngModel)]="newVar">

config

https://github.com/valor-software/ngx-bootstrap/blob/development/src/datepicker/bs-datepicker.config.ts#L31

[bsConfig]="{dateInputFormat: 'yyyy-MM-dd'}" bsDatepicker

note: (v1.9.2) L, en-us locale

+15

, ?

github, , , . , .

bsDatepicker [(bsValue)]="newVar" value="{{ newVar | date:'yyyy-MM-dd' }}"

"yyyy-MM-dd" , bsDatepicker ?

+2

, rangeInputFormat [bsConfig] dateInputFormat.

+2

rangeInputFormat: "YYYY-MM-DD" gives 2019-02-22 - 2019-03-13

0
source

Source: https://habr.com/ru/post/1685478/


All Articles