angular - 如何从 Angular 方法返回 HTML 表达式?
问题描述
所以标题可能不是最好的......但我想到了没有更好的东西:
我想在结果列表中突出显示搜索关键字……这就是为什么我在为这个问题苦苦挣扎的原因。CSS:
highlightText{
font-weight: bold;
}
在打字稿中:
myVariable = "hello world";
keyword=" bonjour";
highlightText(text: string){
return text.replace(keyword, "<span class='highlightStyle'>"+keyword+"</span>");
}
在 HTML 中:
<div>
{{highlightText(myVariable)}}
</div>
在屏幕上我看到整个文本..:
<span class='highlightStyle'>bonjour</span> 世界
但是我真的很期待: bonjour world
yuhhuu 就是这样 :D
任何的想法?
谢谢,Csaba
解决方案
最好使用管道 - 性能更高(函数针对每个更改检测周期运行,而管道仅在其输入参数更改时运行)
推荐阅读
- r - 为什么当将列表传递给 measure.vars 时,melt 会产生警告?
- forms - Symfony 渲染一个集合表单类型原型
- javascript - 在 Next.js 中获取表单提交数据的最佳方法是什么?
- javascript - React Native 中的 BackHandler 无法正常工作
- laravel - Laravel - 用户验证 ID 给出错误响应
- swiftui - 在点击按钮时更改视图的 ViewModel 会导致:“AttributeGraph:通过属性警告检测到循环”
- sql-server - SQL Server:使用 ROW_NUMBER 函数进行分页时出现转换错误
- azure - 无法使用 Microsoft Teams 消息扩展下载文件
- r - 运行应用程序没有结果 R 闪亮的应用程序和崩溃 RStudio
- javascript - 我的路线使用 axios 返回 404 错误