我已经实现了使用angular2来限制输入字段的指令.它在桌面浏览器中工作正常,但在android mobile中无法正常工作.
import { LimitToDirective } from '../../../directives/limitedvalidation';
@Component({
templateUrl: 'build/pages/profile/change-basic-details/change-basic-details.html',
directives: [LimitToDirective]
})
export class UpdateBasicDetailsPage {
constructor(){}
}
Run Code Online (Sandbox Code Playgroud)
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();
}
}
Run Code Online (Sandbox Code Playgroud)
<ion-input limit-to="12" type="tel" [formControl]="aadhaarno">
Run Code Online (Sandbox Code Playgroud)
ran*_*al9 10
使用maxlength如下:
<ion-input [maxlength]="12" type="tel" [formControl]="aadhaarno">
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
17937 次 |
最近记录: |