我想在用户输入时自动大写输入字段中的所有字母。是否有可能使用如何使用Angular formly自动填充全局输入文件
formlyConfigProvider.setWrapper
有没有什么办法在全球采用了棱角分明formly做的一样吗?
我想在用户输入时自动大写输入字段中的所有字母。是否有可能使用如何使用Angular formly自动填充全局输入文件
formlyConfigProvider.setWrapper
有没有什么办法在全球采用了棱角分明formly做的一样吗?
使用角度形式,只需在该字段添加watcher.listener即可。
ctrl.fields = [{
key: 'lastname',
type: 'input',
templateOptions: {
label: 'Last name',
placeholder: 'Ex: PETERSON'
},
watcher: {
listener: function(field, newValue, oldValue, formScope, stopWatching) {
console.log('watch lastname', arguments);
formScope.model.lastname = formScope.model.lastname.toUpperCase();
}
}
},
...
好吧,我不擅长formlyConfigProvider.setWrapper,但我有一个很好的指令autocapitalise的输入数据
angular
.module('myApp', [])
.directive('capitalize', function() {
return {
require: 'ngModel',
link: function(scope, element, attrs, modelCtrl) {
var capitalize = function(inputValue) {
if (inputValue == undefined) inputValue = '';
var capitalized = inputValue.toUpperCase();
if (capitalized !== inputValue) {
modelCtrl.$setViewValue(capitalized);
modelCtrl.$render();
}
return capitalized;
}
modelCtrl.$parsers.push(capitalize);
capitalize(scope[attrs.ngModel]); // capitalize initial value
}
};
});
只需将该指令添加到输入字段,我知道这是一些低劣的但工作很好