javascript - AngularJS ng-bind-html 不适用于表达式
问题描述
我正在尝试评估 ng-bind-html 中的表达式,但它不起作用。如果有人知道解决方法,请提供帮助。
下面的代码没有显示任何内容。
<h5 ng-bind-html="{{feedType ==='popularProducts' ? displayedProduct.title : displayedProduct.name}}"></h5>
解决方案
该ngBindHtml
指令期望属性值作为表达式,因此不需要{{}}
插值。只需删除这些大括号,以便将表达式直接传递给指令。
工作语法:
<h5 ng-bind-html="feedType === 'popularProducts' ? displayedProduct.title : displayedProduct.name"></h5>
适用的 AngularJS文档
推荐阅读
- python - 我卸载了所有 python 版本,但是当我输入 python 时它仍然存在。如何解决?
- excel - 如果选中/取消选中复选框,则更改公共变量的值
- javascript - 页面重新加载时如何使存储在本地存储中的表持久化
- python - TfidfTransformer 和停用词
- java - spring 具有相同请求参数的多个端点
- python - 在 Neat Columns/Table 中打印列表列表
- reactjs - 无法在反应项目中安装 Firebase
- sql - 在缺少数字的序列中插入一个数字
- reactjs - React-bootstrap 还是 mdbootsrap?
- jsp - 提交删除按钮时我需要删除登录用户详细信息,我该如何在jsp中做到这一点