Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何将自定义管道应用于ngFor迭代元素_Javascript_Html_Angular6 - Fatal编程技术网

Javascript 如何将自定义管道应用于ngFor迭代元素

Javascript 如何将自定义管道应用于ngFor迭代元素,javascript,html,angular6,Javascript,Html,Angular6,我有一个自定义管道来突出显示文本。我想将此管道应用于ngfor迭代元素。我该怎么做 这是我的密码: 从'@angular/core'导入{PipeTransform,Pipe}; @管道({name:'highlight'}) 导出类HighlightPipe实现PipeTransform{ 转换(文本:字符串,搜索):字符串{ 如果(搜索和文本){ 让pattern=search.toString().replace(/[\-\[\]\/\{\}(\)\*\+\?\.\\\^\$\\\\\;

我有一个自定义管道来突出显示文本。我想将此管道应用于ngfor迭代元素。我该怎么做

这是我的密码:

从'@angular/core'导入{PipeTransform,Pipe};
@管道({name:'highlight'})
导出类HighlightPipe实现PipeTransform{
转换(文本:字符串,搜索):字符串{
如果(搜索和文本){
让pattern=search.toString().replace(/[\-\[\]\/\{\}(\)\*\+\?\.\\\^\$\\\\\;]/g,\\$&');
模式=模式。分割(“”)。过滤器((t)=>{
返回t.length>0;
}).加入(“|”);
const regex=new RegExp(模式'gi');
返回text.toString().replace(regex,(match)=>`${match}`);
}否则{
返回文本;
}
}
}
:主机::ng deep.搜索突出显示{
背景色:#F2E366;
}

{{item.name}
{{item.path}
{{item.dateModification}日期:'short':'':'fr'}

在@ChellappanV注释之后,特别是在这里,我在search.component.html中更改了代码,如下所示:

{{item.name}}

而不是:


{{item.name}

你是否在你的管道组件中获得了searchTerm数据?@ChellappanV,我不这么认为。这里是stackblitz中的链接stackblitz被破坏了。你能像这样更改你的应用程序代码{item.name}我需要在组件.ts中导入pipe.ts吗?