I've been working on creating a custom pipe that replaces one character with another, like changing hyphenated words to space separated words. However, despite following online tutorials and the Angular documentation, I can't seem to get it to work properly.
Check out my code on StackBlitz
pipe.ts
@Pipe({
name: 'replace'
})
export class ReplacePipe implements PipeTransform {
transform(value: string, replace: string, withThis: string): any {
return value.replace(replace, withThis);
}
}
html usage
<!-- hyphenate = 'some-hyphenated-string' -->
<div>{{hyphenated | replace: {replace: '-', withThis: ' '} }}</div>