问题描述
这是我的 CustomPipe 代码:
这里,文本是一大块字符串。 searchColl
是需要在其中突出显示的单词集合。
这运行良好并突出显示了文本中的所有单词,但它在呈现的文本上附加了 "SafeValue must use [property]=binding"
,如下所示:
transformAddress(text: any,searchColl) {
searchColl.forEach(search => {
if (search !== undefined && search !== null) {
search = search.toString().replace(/[.*+?^${}()|[\]\\]/g,'\\$&');
}
text += '';
var tempText = this._sanitizer.bypassSecurityTrustHtml(search ? text.replace(new RegExp(`(${search})`,'gi'),'<span style="background-color: blue">' + `$1` + '</span>') : text);
text = tempText; // After 1st word from collection is highlighted search this becomes the new input.
});
return this._sanitizer.bypassSecurityTrustHtml(text);
}
这是我在组件代码中使用它的方式:
var retPipeData = this.highlightPipe.transformAddress(source,itemsToSearch);
console.log('DataFromPipe',retPipeData);
// var massagedData = retPipeData.toString().replace('SafeValue must use [property]=binding:','');
// var massagedHTML = this.sanitizer.sanitize(SecurityContext.HTML,this.sanitizer.bypassSecurityTrustHtml(massagedData));
// console.log('massagedDataAfterreplace',massagedData);
// console.log('massagedHTML',massagedHTML);
this.tab1Response = retPipeData;
我也试图从从 Pipe 收到的字符串中删除这个字符串,但这也不起作用(请参阅上面的注释代码)。
另外,我什至尝试过:
this._sanitizer.sanitize(SecurityContext.HTML,this._sanitizer.bypassSecurityTrustHtml(text))
但没有成功。
谁能指出我做错了什么。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)