javascript - html 上的插值内容以字符串格式出现
问题描述
角度版本 1.4
所以我有这个代码 html
<div>{{ isConditionTrue() ? '<p>Some content<p>' : '<p>some other content</p>'}}</div>
组件.js
$scope.isCondition = function(){
return true;// lets say.
}
但是在 UI 上,整个插值是以字符串形式出现的
<div>"{{ isConditionTrue() ? '<p>Some content<p>' : '<p>some other content</p>'}}"</div>
更新:
这些值有时是 string 有时是 html 。那么如何使其通用。有人帮忙!!!T_T
解决方案
你需要使用ng-bind-html
.
看法
<div ng-bind-html="isConditionTrue()"></div>
JS
$scope.isConditionTrue = function() {
if (true) {
return '<p>IF content<p>';
} else {
return '<p>ELSE content<p>';
}
}
如果您遇到任何问题,请告诉我。
推荐阅读
- kubernetes - Kubernetes 生态系统中的 YAML 配置文件是什么?
- reactjs - 如何在 React 中自定义获取 url?
- r - ggplot 指数平滑,调整参数在 exp 内
- c++ - 在类构造函数中使用 MFC 按钮控件 EnableWindow 方法时“调试断言失败”
- linux - 如何将设置变量从 bash 转换为 tcsh
- arangodb - ArangoDB 如何实现高效的图遍历
- python - 如何在 mongo db string 数据类型中插入双引号以存储博客文章?
- python - PyQt5 更改 QAbstractTableModel 中的 BackgroundRole 设置
- python - 使用 pandas 将 csv 文件转换为类似 JSON 的嵌套文件
- python - 如何在图表上叠加/移动轴?