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';
});
You 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With