Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular ngModel format output

Tags:

angular

This is my HTML code:

<div class="form-group">
  <label class="form-control-label" for="field_start">Start</label>
  <input type="datetime-local" class="form-control" name="start" id="field_start" [(ngModel)]="service.startDate" />
</div>

Therefore, startDate is stored as a number (Long) but I want to display a datetime-local. I have really no idea how to do it. I'm using the same component for creating and updating a model. Creating is working cause I can manipulate the value in the called function.

like image 674
1thingtodo Avatar asked Aug 19 '26 09:08

1thingtodo


1 Answers

You can change 2-way binding [(ngModel)] to separate property and event bindings using [ngModel] and (ngModelChange). Then you can use a pipe to format input value.

Using Pipes within ngModel on INPUT Elements in Angular

like image 74
Shivam Sinha Avatar answered Aug 21 '26 00:08

Shivam Sinha



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!