2016-03-21 48 views

回答

0

使用角度形式,只需在该字段添加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(); 
     } 
    } 
}, 
... 
0

好吧,我不擅长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 
     } 
    }; 
    }); 

只需将该指令添加到输入字段,我知道这是一些低劣的但工作很好

相关问题