Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why does angularJS treat spaces as empty? [duplicate]

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?

like image 487
9blue Avatar asked Apr 15 '14 14:04

9blue


1 Answers

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"/>
like image 50
Sai Avatar answered Oct 30 '22 17:10

Sai