I am working on developing a customized pipe in Angular 2 that will handle the replacement of the backslash ('\') character in a given string. This backslash is commonly used to escape special characters.
What I have accomplished so far:
The pipe class looks like this:
@Pipe({
name: 'escapeSlashPipe'
})
export class EscapeSlashPipe implements PipeTransform {
transform (value: string): any{
value = value.replace(/\\"/g, '"');
return value;
}
}
Here is how it is implemented in HTML:
<p>{{message | escapeSlashPipe}}</h4>
For example, if the input string is:
"ghda\'nja asda\\dasda dasj\' \"das\'da\\d as\\as\\sad"
After applying the pipe, the output should be:
"ghda'nja asda\dasda dasj' das'da\d as\as\sad"
The main objective of this pipe is to selectively replace only those backslashes that are used for escaping characters.