How to remove whitespace in text

后端 未结 5 1211
夕颜
夕颜 2021-01-17 18:01

How can I trim a text string in my Angular application?

Example

{{ someobject.name }}  

someobject.name results in \"name abc\"

5条回答
  •  隐瞒了意图╮
    2021-01-17 18:24

    import { Pipe, PipeTransform } from '@angular/core';
    
    @Pipe({
      name: 'removeWhiteSpace'
    })
    export class RemoveWhiteSpacePipe implements PipeTransform {
    
      transform(value: any): any {
        if (value === undefined)
          return 'undefined';
        return value.replace(/\s/g, "");
      }
    
    }
    

提交回复
热议问题