I get html entities from json file, like: ’
How can I unescape it in html component?
I created custom pipe, but it works only for entities like &
:
import { Pipe, PipeTransform } from '@angular/core';
import {unescape} from 'lodash';
@Pipe({
name: 'unescape'
})
export class UnescapePipe implements PipeTransform {
transform(value: any, args?: any): any {
return unescape(value);
}
}
The solution, create next custom pipe:
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'unescape'
})
export class UnescapePipe implements PipeTransform {
transform(value: any, args?: any): any {
const doc = new DOMParser().parseFromString(value, 'text/html');
return doc.documentElement.textContent;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With