我有以下 html:
<input type="text" ng-model="skype" ng-change="checkInput('skype')">
函数是:
$scope.checkInput = function(value) {
var string = $scope[value],
pattern = /[^a-zA-Z]+/g;
string = string.replace(pattern, '');
}
现在 console.log 显示字符串已成功替换,但是 View 没有更新。 最奇怪的部分是当使用子字符串时 View 更新!
string = string.substring(0, 10);
怎么了?
最佳答案
您没有为范围设置任何值,以便 Angular 可以观察并对此使用react,您的函数正在做某事但从未为范围设置值。
$scope.checkInput = function(value) {
var string = $scope[value],
pattern = /[^a-zA-Z]+/g;
$scope.skype = string.replace(pattern, '');
}
关于javascript - 替换值时 AngularJS View 不更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38825759/