I have a component with input text field to which I have attached an input event listener using JQuery. When the value of the input changes I want to call a Typescript function but it throws an uncaught TypeError.
Here is my code:
import {Component, Input, Output, EventEmitter, ElementRef, OnInit} from 'angular2/core';
declare var jQuery: any;
@Component({
selector: 'setting-priority',
template: '<input [(ngModel)]="priority" class="setting-priority" type="text">'
})
export class SettingPriorityComponent implements OnInit{
@Input() priority: number;
@Output() prioChanged: EventEmitter<number> = new EventEmitter();
constructor(private elementRef:ElementRef) { }
ngOnInit() {
jQuery(this.elementRef.nativeElement).find('input').on('input', function() {
// Here I will pass the changed value to onChange function
this.onChange();
});
}
ngOnChanges(changes) {
this.prioChanged.emit(this.priority);
}
// In this function I will receive the value and assign it to the priority variable
onChange() {
console.log("onchange!");
}
}
I'm using Jquery because the input value will be set programmatically - in this case Angular's Change Detection doesn't work Details here
When I trigger the input event, I receive an Uncaught TypeError: this.onChange is not a function
What am I doing wrong?