我尝试这样做:
<div id="{{mystring.replace(/[\s]/g, \'\')}}"></div>
但它不起作用。 “mystring”是 $scope
上的一个对象,其字符串类似于“my string is this”,其中包含我想从 View 中删除的空格。
最佳答案
只需创建一个专用过滤器:
angular.module('filters.stringUtils', [])
.filter('removeSpaces', [function() {
return function(string) {
if (!angular.isString(string)) {
return string;
}
return string.replace(/[\s]/g, '');
};
}])
并这样调用它:
<div id="{{'hi there'| removeSpaces}}"></div>
关于angularjs - 如何删除 AngularJS 绑定(bind)中的所有字符串空格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26232826/