Is there a way to create an Observable from an Ionic 2 form element without directly accessing the DOM?
While the Observable.fromEvent function is useful for events, I have the form element reference from the FormBuilder service, not the actual element itself. I could pull it from the DOM, but I'm curious if there is a more efficient method available.
My current setup
I define form elements using the Form Builder service:
this.myForm = this.fb.group({
elem1: new FormControl('elem1'),
elem2: new FormControl('elem2'),
elem3: new FormControl('elem3'),
elem4: new FormControl('elem3')
});
this.formInputElem1: AbstractControl = this.myForm.get('elem1');
Usually, I would use:
Observable.fromEvent(this.formInputElem, 'ionChange');
However, I encounter an issue where the first parameter of Observable.formEvent should be EventTargetLike, but the form element is an AbstractControl.
I have attempted to cast formInputElem1 to a FormControl and searched for any functions that return the DOM element or an EventTargetLike without success.
The definition of EventTargetLike specifies "The DOMElement, event target, Node.js, EventEmitter, NodeList or HTMLCollection to attach the event handler to."
So, the question remains: How can I create an observable from an Ionic 2 input form element?