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?

Était-ce utile?

La 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"/>
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top