最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - why white space are getting ignored in AngularJS application - Stack Overflow

programmeradmin3浏览0评论

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 ?

Fiddled here

Thanks

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 ?

Fiddled here

Thanks

Share Improve this question asked Apr 17, 2015 at 9:30 TharifTharif 14k10 gold badges57 silver badges78 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 7

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

Use ng-trim="false" directive:

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

DEMO: http://jsfiddle/pa6sdudd/4/

发布评论

评论列表(0)

  1. 暂无评论