如何删除前导和输入文本尾随空格? [英] How to remove leading and trailing white spaces from input text?
问题描述
我需要修复AngularJS应用程序,其中有许多形式提交数据错误 -
I need to fix a bug in AngularJS application, which has many forms to submit data-
在形式每个文本框接受空格(前沿和后),并将其保存到数据库中。因此,为了解决这个问题我用 NG-修剪=真正的
,它的工作和数据是越来越在后端正确保存。
Every Text box in forms is accepting whitespaces(both leading and trailing) and saving them into the database. So in order to fix this I used ng-trim="true"
, it worked and data is getting saved correctly in the back-end.
问题:即使使用NG-修剪后,当我点击保存/更新,表单的用户界面显示了白色的空间不是修剪数据的文本。它显示了正确的数据,只有当我刷新页面。
Problem: Even after using ng-trim when I click on save/update, the form UI shows the text with white-spaces not the trimmed data. It shows correct data only when I refresh the page.
任何人都可以指导我..什么将是解决这一问题的办法?
Can anyone guide me.. what will be the approach to fix this?
P.S。 - !我是新来的JavaScript和角
P.S. - I'm new to both JavaScript and Angular!
感谢
推荐答案
使用字符串= string.trim()
,其中字符串
是变量牵着你的字符串值。
Use string = string.trim()
where string
is the variable holding your string value.
这篇关于如何删除前导和输入文本尾随空格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!