0

How to format the data just for viewing, but keep the value the way it is?

I have this method that formart the value:

formataNomeGrupo(listaGrupoAnaliseCae: SelectItem[]) : any {
         listaGrupoAnaliseCae.forEach((nomeGrupo:SelectItem)=>
             {nomeGrupo.label = nomeGrupo.label.toLowerCase().replace(/(?:^|\s)(?!da|de|do|e)\S/g, l
 => l.toUpperCase());
         });
         return listaGrupoAnaliseCae;
 
     };

I call this method here on html :

[options]="formataNomeGrupo(listaGrupoAnaliseCae)"

For example i have a word, like "DOLAR", and I format this to "Dolar". But i want to keep the value "DOLAR" on my typescript.

1 Answers1

0

try to use custom pipe

import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
   name: 'lower',
   pure: false
})
export class PersonelFilterPipe implements PipeTransform {
  transform(param: string): any { 
     return param.toLowerCase().replace(/(?:^|\s)(?!da|de|do|e)\S/g, l=> l.toUpperCase());
   }
}

in your html write like <div>{{label | lower}}</div>

mr. pc_coder
  • 16,412
  • 3
  • 32
  • 54