I want to add ` every 3 occurrences from the back of the string. For example, instead of 1000 in input, I want to have 1'000.
Heading
#
html but value be 1000 in angular
I want to add ` every 3 occurrences from the back of the string. For example, instead of 1000 in input, I want to have 1'000.
Heading
html but value be 1000 in angular
import { Pipe, PipeTransform } from '@angular/core';
import { DatePipe } from '@angular/common';
@Pipe({
name: 'customNumbPipe',
})
export class customNumbPipe implements PipeTransform {
transform(value: string): string {
return value.toString().replace(/(.{3})/g,"`1")
}
}
Then you can use the pipe like this {{ displayValue | customNumbPipe}}
I got that regex from here. It inserts an ` every 3 occurrences.
edit:
value
's type from number | string
to string
you could do something like this:
<input id="name" type="text" value="1000">
but the moment your users changed the value by entering something (in that input field) than your "value" would be gone replaced with what was entered. you could write javascript that listened for change in the input field and at that time assign the value you need to the data you are collecting.