Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why white space are getting ignored in AngularJS application

AngularJS application:

The ng-model directives bind the input fields to the controller properties.In my application the inputs with spaces are ignored, for example : " A",the resulting output is "A".

Is there a way to include those white spaces as well ?

enter image description here

Fiddled here

Thanks

like image 416
Tharif Avatar asked Apr 17 '15 09:04

Tharif


2 Answers

You can add the ng-trim="false" attribute to stop Angular from trimming the extra whitespace in input fields.


Besides that, you also have the additional problem that the whitespace isn't rendered in HTML.

You can fix this for example by using

Full Name: <pre>{{Location + " " + Item}}</pre>

Demo fiddle

Or alternatively by using css:

white-space: pre;

Demo fiddle

like image 90
Praxis Ashelin Avatar answered Oct 18 '22 04:10

Praxis Ashelin


Use ng-trim="false" directive:

<input type="text" ng-model="Location" ng-trim="false">

DEMO: http://jsfiddle.net/pa6sdudd/4/

like image 38
VisioN Avatar answered Oct 18 '22 04:10

VisioN