angularjs force uppercase in textbox

前端 未结 14 1824
情歌与酒
情歌与酒 2020-11-30 20:47

I\'ve tried using the uppercase filter but it does not work. I\'ve tried doing it two ways:


<         


        
14条回答
  •  无人及你
    2020-11-30 21:09

    This will not work at all.

    ng-model is for specifying which field / property from the scope should be bound to the model. Also, ng-model does not accept an expression as value. Expressions in angular.js are things between {{ and }}.

    The uppercase filter could used in the output and everywhere where expressions are allowed.

    You cannot do what you want to do, but you could use CSS's text-transform to at least display everything in uppercase.

    If you want to have the value of a text field in uppercase letters you can achieve this with some custom JavaScript.

    In your controller:

    $scope.$watch('test', function(newValue, oldValue) {
      $scope.$apply(function() {
        $scope.test = newValue.toUpperCase();
      }
    });
    

提交回复
热议问题