我从 json 文件获取 html 实体,例如:’
如何在 html 组件中取消转义它?
我创建了自定义管道,但它仅适用于像&
:
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);
}
}
解决方案,创建下一个自定义管道:
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;
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)