问题描述
有一个角特定的方式?如果不是这样,我应该使用内置的jQuery来做到这一点?如果我应使用内置jQuery中我该如何去修剪()函数不使用$(或者是必需的)?
Is there an angular specific way? If not, should I use the built in jquery to do it? If I should use the built in jquery how do I get to the trim() function without using $ (or is that necessary)?
编辑 - 是的,我知道str.trim()。抱歉。我需要这个IE 8中工作。
Edit - Yes I know about str.trim(). Sorry. I need this to work in IE 8
编辑 - 至于这个问题是一个重复的,我是问具体怎么做到这一点的角度,其中所引用的回答解释了如何做到这一点在JavaScript中,节点和jQuery。有没有办法使用内置jQuery中的角度做呢?
Edit - As far as this question being a duplicate, I am asking specifically how to do this in angular where the answer referenced explains how to do it in javascript, node and jquery. Is there a way to do it using the built in jquery in angular?
编辑 - 很显然,答案是AngularJS并没有做到这一点
Edit - Apparently the answer is "AngularJS doesn't do this"
推荐答案
如果你只需要的显示的剪裁后的值,那么我建议对操纵原始字符串并使用的代替。
If you need only display the trimmed value then I'd suggest against manipulating the original string and using a filter instead.
app.filter('trim', function () {
return function(value) {
if(!angular.isString(value)) {
return value;
}
return value.replace(/^\s+|\s+$/g, ''); // you could use .trim, but it's not going to work in IE<9
};
});
然后
<span>{{ foo | trim }}</span>
这篇关于我如何修剪()在angularjs字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!