0

This is really basic, but I'm drawing a blank. I'm using ngModel to two-way data-bind to a variable from an input, but I want the value to be transformed on keypress the Angular 2 way. I have pipe that I'm using in another location for the same variable that has the replacement I need. The pipe just converts a title into a string usable as a URL routing slug. I'm not worried about that part. The problem is that pipes don't work with ngModel (as far as I can tell), so I have to do something else, and I can't remember what this is called.

When the user enters invalid characters (numbers, special characters) into a field, I need those characters cleared from both the field and the variable, immediately, so the user will never see them. What is this called, and how do I do it? I already used (keypress), but that didn't clear the characters immediately.

BBaysinger
  • 6,614
  • 13
  • 63
  • 132
  • Can you post code that you've already written? – Fletchius Mar 31 '17 at 19:10
  • 1
    Use should be using directives to achieve these. You can refer to this [**answer**](http://stackoverflow.com/questions/42400175/textbox-on-changes-directive-angular2/42400391#42400391) it also has a demo. Let me know if you need some more help. **Note: if needed you can use keydown event in the directive** – Aravind Mar 31 '17 at 19:19
  • My question is a duplicate of this question: http://stackoverflow.com/questions/37603705/angular-2-input-custom-pipe – BBaysinger Mar 31 '17 at 20:13
  • @BBaysinger so did you fix your issue or need more help – Aravind Apr 01 '17 at 02:59
  • 1
    Possible duplicate of [Angular 2 Input Custom Pipe](https://stackoverflow.com/questions/37603705/angular-2-input-custom-pipe) – FrenchFigaro Apr 19 '18 at 13:29

0 Answers0