'replace a string by another string custom pipe
I have a requirement to create custom pipe for replacing a string to another. If the string is 'true' then i have to display it as 'Yes'. If the string is 'false' then i have to display it as 'No'. I tried creating a custom pipe for it , but its not working.
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({ name: 'replaceText' })
export class ReplaceTextPipe implements PipeTransform {
transform(value: string): string {
if (value) {
console.log(value);
if (value === "true") {
value = value.replace("true", "Yes");
} else {
value = value.replace("false", "No");
}
return value;
}
}
}
Can any one guide me please.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
