Limit the length of input field using angular2
angular
Solution
Use maxlength as belows :
<ion-input [maxlength]="12" type="tel" [formControl]="aadhaarno">
Problem
I have implemented the directive to restrict the input field using angular2. It is working fine in desktop browser, but not working in android mobile. component ``` import { LimitToDirective } from '../../../directives/limitedvalidation'; @Component({ templateUrl: 'build/pages/profile/change-basic-details/change-basic-details.html', directives: [LimitToDirective] }) export class UpdateBasicDetailsPage { constructor(){} } ``` directive ``` import {Directive, Input} from '@angular/core' @Directive({ selector: '[limit-to]', host: { '(keypress)': '_onKeypress($event)', } }) export class LimitToDirective { @Input('limit-to') limitTo; _onKeypress(e) { const limit = +this.limitTo; if (e.target.value.length === limit) e.preventDefault(); } } ``` template ``` <ion-input limit-to="12" type="tel" [formControl]="aadhaarno"> ```