I try to set a handler using fromEvent from RxJS library. I would like to Observe and Subscribe on a "keyup" event on an input field. So i make a function (typescript static method) to handle :
import { fromEvent, map, Subscription } from "rxjs";
import { AbstractControl } from "./../../forms/abstract-control";
export class InputHandler {
public static getKeyupHandler(control: AbstractControl): Subscription {
return fromEvent((control.supportFormField) as HTMLInputElement, 'keyup')
.pipe(
map((event: KeyboardEvent) => {
console.log(`${control.supportFormField.getAttribute('name')} has changed`)
control.value = (control.supportFormField as HTMLInputElement).value
if (control.value.trim().length === 0) {
control.value = ''
}
return control.value
})
)
.subscribe((value: string) => {
console.log(`Value for ${control.controlName} : ${control.value}`)
})
}
}
Expect to have some console, but got nothing at all nor in map neither in subscribe...
Controls are present in the DOM :
<input type="text" name="lastname" required data-rel="lastname">
Don't understand the reason why anything is produced by the fromEvent function.
If any idea...
Regards