admin管理员组文章数量:1194180
When an angular model is bound to an input, Angular doesn't seem to update the value if a space is added. Even if the model is watched, the value still does not update.
I created a JS Fiddle to demonstrate the issue. Type a string, and notice the values in the bound spans update. However, add a space to the end of the string and the value doesn't update. Is there a way to force angular to watch for spaces as well?
The specific code is:
View
<div ng-controller="MyCtrl">
<input data-ng-model="inputValue">
<p>This value: ----<span data-ng-bind="inputValue"></span>----</p>
</div>
Controller
function MyCtrl($scope) {
$scope.inputValue = 'Superhero';
});
When an angular model is bound to an input, Angular doesn't seem to update the value if a space is added. Even if the model is watched, the value still does not update.
I created a JS Fiddle to demonstrate the issue. Type a string, and notice the values in the bound spans update. However, add a space to the end of the string and the value doesn't update. Is there a way to force angular to watch for spaces as well?
The specific code is:
View
<div ng-controller="MyCtrl">
<input data-ng-model="inputValue">
<p>This value: ----<span data-ng-bind="inputValue"></span>----</p>
</div>
Controller
function MyCtrl($scope) {
$scope.inputValue = 'Superhero';
});
Share
Improve this question
asked Feb 18, 2014 at 5:04
Eric Di BariEric Di Bari
3,8677 gold badges42 silver badges49 bronze badges
1 Answer
Reset to default 29You need to set ngTrim
to false. By default Angular sets it to true, which trims white space in input boxes:
<input data-ng-model="inputValue" data-ng-trim="false" />
Fiddle: http://jsfiddle.net/vYLQk/9/
Docs: http://code.angularjs.org/1.2.13/docs/api/ng.directive:input.text
本文标签: javascriptAngular model doesn39t update with spaceStack Overflow
版权声明:本文标题:javascript - Angular model doesn't update with space - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738498879a2090150.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论