Note, I’m new at this an making lots of mistakes but…
Working on a directive, “numbers-only”, that checks for valid numbers and changes background from red to green.
sort of works for angular 2 but must specify color as red, green, not ionic primary, secondary, danger, etc
<input numbers-only (blur)=“evaluateEarnings()” [(ngModel)]=“meeting.earnings” type=“text” [disabled]=“meeting.dollarsPerHrDisabled”>
but this does not.
{{earningsLabel}}Directive code snippet:
@HostListener(‘keyup’, [’$event’])
keyup(e: KeyboardEvent) {
console.log("Key Up! " + e.key);
// }
// @HostListener(‘keypress’, [’$event’])
// keyPress() {
console.log(“In numbers-only directive: keypress”);
if(isNaN(this.el.nativeElement.value.replace(/,/gi, “”))){
//this.el.nativeElement.style.backgroundColor = “danger”;
this.el.nativeElement.style.backgroundColor = “red”;
}else{
this.el.nativeElement.style.backgroundColor = “green”;
}
}
I get error:
error_handler.js:48 EXCEPTION: Error in ./CalcPage class CalcPage - inline template:54:16 caused by: Cannot read property ‘replace’ of undefined
which is from:
if(isNaN(this.el.nativeElement.value.replace(/,/gi, “”)))