对于文本输入字段,maxlength HTML5属性在移动设备上无法正常工作。如果数字键盘已启用,则可以使用,但在使用文本键盘时不起作用。
代码:
<ion-content class="p-l-10 p-r-10 had-header form_page">
<form ng-submit="vm.addAdvance()">
<div class="list">
<label class="item item-input InputFormFull">
<span class="input-label">{{'note_message' | translate}}</span>
<input type="text" placeholder="{{'notes_message' | translate}}"
ng-model="vm.advance.description" id="field2" ng-change="vm.fillStarted()" size="5" maxlength="5" required>
</label>
<button class="button trans-but m-t-10" type="submit">{{'save_message' | translate}}</button>
</div>
</form>
答案 0 :(得分:0)
可能重复:Input maxlength does not work on Android -Ionic
尝试创建自己的指令:
myApp.directive('limitChar', function() {
'use strict';
return {
restrict: 'A',
scope: {
limit: '=limit',
ngModel: '=ngModel'
},
link: function(scope) {
scope.$watch('ngModel', function(newValue, oldValue) {
if (newValue) {
var length = newValue.toString().length;
if (length > scope.limit) {
scope.ngModel = oldValue;
}
}
});
}
};
})
<强> HTML 强>
<input type="text" limit-char limit="5">