Issue
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.
Solution
I think the problem could be that you are passing boolean value as string.
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'replaceText'
})
export class ReplaceTextPipe implements PipeTransform {
transform(value: boolean): any {
return value ? "Yes" : "No";
}
}
Is work progressing: {{isRunning | replaceText }}
Answered By - Abhilash Asokan
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.