我有一个场景,我必须根据其区域设置格式更改数字(用户在输入字段中输入的数字)。我希望该更改立即反射(reflect)在 HTML 中。
就像如果用户输入 23.4 这样的数字,那么在 ng-model 和 html View 中它也应该立即更改为 23,4。
<input type="number" class="form-control" ng-model="vm.newPlayer.weight" ng-class="{'active' : vm.newPlayer.weight}">
这是我的输入字段。
最佳答案
我认为你可以利用 watch 并在值变化时执行所需的操作。
这是一个示例 fiddle ,可以帮助您 http://jsfiddle.net/user2314737/jmf6kL3n/
$scope.myName = "";
$scope.greeting = "h";
$scope.$watch("myName", function (newValue, oldValue) {
//some custom code here
});
关于javascript - 根据 AngularJS 中的区域设置更改输入值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47546986/