I have written a pipe in Angular to replace the character |
with a ,
.
export class AppComponent {
name = 'Name|with|pipes';
}
The desired output is Name,with,pipes
, but I am seeing it as ,N,a,m,e,|,w,i,t,h,|,p,i,p,e,s,
Here's the code for the pipe:
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({name: 'replace'})
export class ReplacePipe implements PipeTransform {
transform(value: string, strToReplace: string, replacementStr: string): string {
if(!value || ! strToReplace || ! replacementStr)
{
return value;
}
return value.replace(new RegExp(strToReplace, 'g'), replacementStr);
}
}
Here's the code on StackBlitz. How can I fix this?