Angular model does not update with space

When the angular model is bound to the input, angular does not seem to update the value if space is added. Even if the model is being viewed, the value is still not updated.

I created JS Fiddle to demonstrate this problem. Enter a line and pay attention to the values ​​in the update borders. However, add a space at the end of the line and the value will not be updated. Is there a way to make angular also observe spaces?

Specific code:

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'; }); 
+8
javascript angularjs
source share
1 answer

You need to set ngTrim to false. By default, Angular sets to true, which justifies the space in the input field:

 <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

+23
source share

All Articles