简体   繁体   English

使用Angular过滤器突出显示搜索结果并隐藏不匹配的文本?

[英]Highlight search result with Angular filter and hide non matching text?

I found this example for highlighting a search result using Angular filter, the thing is that when you search for example 'suit' it highlight the word suit but all the non-matching text is still there. 我发现此示例使用Angular过滤器突出显示搜索结果,但事实是,当您搜索“西装”时,它会突出显示“西装”一词,但所有不匹配的文本仍然存在。

http://demo.codeforgeek.com/highlight-angular/ http://demo.codeforgeek.com/highlight-angular/

How I can hide all text except the highlighted text and two or three word before and after this one? 如何隐藏除突出显示的文本和该文本前后两个或三个单词以外的所有文本?

Just change the <style> part with below code: 只需使用以下代码更改<style>部分:

<style>
  .highlighted { color:#000; background: yellow }
  div.container ul div { color:#fff }
</style>

this should do the trick. 这应该可以解决问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM