1thingtodo
1thingtodo

Reputation: 95

Angular ngModel format output

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.

Upvotes: 3

Views: 6687

Answers (2)

Suresh Kumar Ariya
Suresh Kumar Ariya

Reputation: 9754

You can try angular-moment library which supports converting datetime to local to your timezone.

var a = moment.utc([2011, 0, 1, 8]);
a.local();

Upvotes: 0

Shivam Sinha
Shivam Sinha

Reputation: 143

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

Upvotes: 3

Related Questions