How do I trim() a string in angularjs?

后端 未结 5 1945
误落风尘
误落风尘 2021-02-05 08:51

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 $ (o

5条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-05 09:04

    JS .trim() is supported in basically everthing, except IE 8 and below.

    If you want it to work with that, then, you can use JQuery, but it'll need to be <2.0.0 (as they removed support for IE8 in the 2.x.x line).

    Your other option, if you care about IE7/8 (As you mention earlier), is to add trim yourself:

    if(typeof String.prototype.trim !== 'function') {
      String.prototype.trim = function() {
        return this.replace(/^\s+|\s+$/g, ''); 
      }
    }
    

提交回复
热议问题