2

This is my HTML:

<input [(ngModel)]="ask.start" type="number" min="0"/>

I need to use type="number" because user will have a question like

"In how many days do you want to see this"

then comes the input.

the [(ngModel)] value is number of days. I need to convert it to milliseconds somehow, so I can get the milliseconds value and store it.

EDIT: the formula for 1 day in ms is 24 * 60 * 60 * 1000

How can I do this? I've been loosing my mind over this for days now.

Thanks.

eric.dummy
  • 399
  • 1
  • 8
  • 24

1 Answers1

2

You should create a custom pipe.

@Pipe({ name: 'myPipe'})
export class MyPipe implements PipeTransform{
  transform(val) {
    return val * 24 * 60 * 60 * 1000
  } 
}

Change your input like this:

<input [(ngModel)]="ask.start | myPipe" type="number" min="0"/>

Related question: Using Pipes within ngModel on INPUT Elements in Angular2-View

Community
  • 1
  • 1
OddDev
  • 3,644
  • 5
  • 30
  • 53