I know that you can use the valueChanges observable in Angular Reactive Forms to detect if a value in the input field has already changed:
inputControl.valueChanges.subscribe(() => {
// fires when the input value has actually changed
});
However, is there a way to subscribe to an observable of when the user has pressed a key, before the value changes in the input?
I need to do this so I can apply dynamic validation, for example:
is there a way to subscribe when the user has pressed a key, before the value changes in the input?
onkeyup event :
<input formControlName="yourcontrol" (keyup)="onKeyUp($event)">
You need subscribe to event keyup
on your AbstractControl elememnt .
see the stackblitz
You could also create a directive to access your element using ElementRef
regarding what your requirements are.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.