简体   繁体   English

角度输入类型日期:如何获取当前日期预设?

[英]Angular input type date: how to get the current date preset?

I have the following HTML:我有以下 HTML:

<div class="form-group">
  <label for="regDate">Registration date:</label>
  <input id="regDate" name="regDate" class="form-control" required type="date" #nameField="ngModel" [(ngModel)]="weightData.regDate">
  {{ weightData.regDate | date: 'dd/MM/yyy' }}
</div>

I'm using Angular, but for this first test I just want to use regular input fields.我正在使用 Angular,但对于第一个测试,我只想使用常规输入字段。 I've set weightData.regDate to today's date.我已将 weightData.regDate 设置为今天的日期。 The interploation with the pipe is working fine.与管道的插入工作正常。 But in the input field I keep getting "dd-----yyyy".但是在输入字段中,我不断收到“dd-----yyyy”。 How can I set the correct date with binding immediately?如何立即通过绑定设置正确的日期?

在此处输入图片说明

I've put up an example on StackBlitz: https://stackblitz.com/edit/angular-1gqxq1我在 StackBlitz 上举了一个例子: https ://stackblitz.com/edit/angular-1gqxq1

You need to use the date pipe to format the date as follows,您需要使用日期管道来格式化日期,如下所示,

 <input  type="date" id="regDate" name="regDate" class="form-control" required type="date" #nameField="ngModel"  [ngModel]="regDate | date:'yyyy-MM-dd'"  >

STACKBLITZ DEMO STACKBLITZ 演示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM