首页 > 解决方案 > 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

标签: javascriptangularjsinterpolation

解决方案


你需要使用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>';
  }
}

如果您遇到任何问题,请告诉我。


推荐阅读