I have a simple Angular 2 directive that changes the input value of a text field. Note that I am using a form approach with a model.
@Directive({ selector: '[appUpperCase]' }) export class UpperCaseDirective{ constructor(private el: ElementRef, private control : NgControl) { } @HostListener('input',['$event']) onEvent($event){ console.log($event); let upper = this.el.nativeElement.value.toUpperCase(); this.control.valueAccessor.writeValue(upper); } }
The domain is updated correctly, but the model is updated after each keystroke. Take a look at plnkr
source share