Вопрос

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?

Это было полезно?

Решение

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"/>
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top