【发布时间】:2018-06-01 11:01:38
【问题描述】:
我对 Angular 2 很陌生。我正在尝试完成与上述帖子中提到的 Highlight the search text - angular 2 相同的任务。 我已经创建了管道过滤器,我的问题是我应该在哪里保留管道过滤器以及应该在哪里放置内部 html div。
复制问题:
信使会根据用户输入的内容显示搜索结果。需要在显示结果的同时突出显示正在搜索的单词。这些是使用的html和组件。
component.html
<div *ngFor = "let result of resultArray">
<div>Id : result.id </div>
<div>Summary : result.summary </div>
<div> Link : result.link </div>
</div>
组件.ts
resultArray : any = [{"id":"1","summary":"These are the results for the searched text","link":"http://www.example.com"}]
这个 resultArray 是通过发送搜索文本作为输入从命中后端服务中获取的。根据搜索文本,获取结果。需要高亮搜索到的文字,类似于google搜索。
我应该如何应用搜索过滤器以及我应该在哪里保留内部 html?
【问题讨论】:
-
您是否尝试过获取子字符串并使用突出显示文本所需的 HTML TAG 对其进行标记?
标签: html angular typescript pipe