Question

In angularJS, I have a input field bind with ng-model, have something show if input is not empty.

<input id="name" type="text" ng-model="typeSignature" placeholder="Type your name here">
<div ng-show="typeSignature==''"> Something</div>

When I press space key, the boolean of typeSignature=='' is still true. However, in jQuery the boolean $('#name').val() == '' will be false if I have pressed space.

Why is angularJS treating space differently? How can I make jQuery val() function consistent with anguLarJS, namely treating space as empty as well?

Was it helpful?

Solution

The default behavior of angular is to trim the model value. So, if you want to listen to space in model you can set the flag ng-trim="false"

<input ng-model="test" ng-trim="false"/>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top