Dear All,
I have built a custom directive that limit the numbers of characters in an input field. This directive works on android 4.2.2 but not on android 5.1.1.
Can someone please advise?
Ashley
Dear All,
I have built a custom directive that limit the numbers of characters in an input field. This directive works on android 4.2.2 but not on android 5.1.1.
Can someone please advise?
Ashley
Can someone help please?
Thanks.
Below is my code
import { Directive, Input, HostListener } from ‘@angular/core’;
/*
Generated class for the LimitTo directive.
See https://angular.io/docs/ts/latest/api/core/index/DirectiveMetadata-class.html
for more info on Angular 2 Directives.
*/
@Directive({
selector: ‘[limit-to]’ // Attribute selector
})
export class LimitTo {
@Input(‘limit-to’) limitTo;
constructor() {
}
//HostListener decorator handle event handlers for input (onKeyPress)
@HostListener(‘keypress’, [’$event’])
onkeypress(ev) {
const limit = +this.limitTo; //convert to number
// once it reaches the limit set, stop propgating event.
if (ev.target.value.length === limit) {
ev.preventDefault();
}
}
}
Hello Everyone,
Badly need some hint.
Ashley