10

I want when user typing in input execute a function,like this :

<input
   id="cell"
   type="text"
   name="cell"
   ngControl="cell"
   (change)="topersian($event)"
>

topersian($event){
  $event.currentTarget.value = $event.currentTarget.value.toPersianNumber();
}

I don't want to use (keypress) or (keyup) because user can see the English number.

I use [(ngModelChange)] but can't access to $event, just get value! how to fix this problem ? or anybody have A better solution?

5
  • Can you elaborate a bit more what the problem with (keypress) and (keyup) is? Commented Jun 12, 2016 at 13:57
  • user can see the changes...i mean have delay 1 convert to 1 persian...Do you understand?
    – user5738822
    Commented Jun 12, 2016 at 13:59
  • What about (keydown) then? Commented Jun 12, 2016 at 14:00
  • The problem with the change event seems to be stackoverflow.com/a/21042928/217408 The chrome bug still doesn't seem to be fixed. Commented Jun 12, 2016 at 14:00
  • yes keydown have problem like this...aaah shit
    – user5738822
    Commented Jun 12, 2016 at 14:11

2 Answers 2

22

Looks like Change event not firing on text input using jquery in Chrome

The input event should do what you want

<input (input)="topersian($event)>
0
3

You can also use

(ngModelChange)="topersian($event)