我有以下情况
我的输入文本框将包含一个文本值,假设它是小写的“ sampletext ”。
<input type="text" ng-model="txtValue" />
因此,当用户输入 s 文本框值时, S
用户再次输入 a 所以现在文字将 Sa ,它应该改为 SA
简单的单词在他输入的下一个字符之前应该变成大写。
我在两个不同的文本框中尝试了类似这样的内容,如下面的代码
Before
<input type="text" ng-model="numberValue"/>
After
<input type="text" ng-model="numberVal"/>
脚本控制器
$scope.$watch('numberValue',function(){
$scope.numberVal=parseInt($scope.numberValue).toUpperCase();
});
如果我需要将它们与示例A =&gt;分开,该怎么办? “A”Ab =&gt; “A”,“B”之类的 此
答案 0 :(得分:1)
如果您想要进行可见的更改,可以这样做:Fiddle
Html:
<div ng-app="myApp" ng-controller="Ctrl">
<input type="text" ng-model="message" ng-change="toUpperCase()"/>
</div>
控制器:
angular.module("myApp", [])
.controller('Ctrl', function ($scope, $timeout){
$scope.toUpperCase = function (){
$timeout(function (){
$scope.message = $scope.message.toUpperCase();
}, 100)
}
});