简体   繁体   中英

Set input field placeholder from Date()

I would like to dynamically set <input type='date' placeholder='{{ 'currentDate' }}'> placeholders, and my variable currentDate is currentDate = this.datePipe.transform(new Date(), "yyyy-MM-dd"); , but this method does not work.

How does one use this to dynamically set placeholder currently dates?

Replace {{ 'currentDate' }} => {{ currentDate }}

I would recommend to use bindings for inserted dynamic values instead of string interpolation. Also use the datepipe in the recommendef way.

<input type="date" [placeholder]="currentDate | date:'yyyy-MM-dd'" ...>


// in the *.ts

public currentDate: Date = new Date();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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