当字符串在模板上时,来自 angularjs 中的字符串的 'Echo' html

'Echo' html from string in angularjs when the string is on a template

本文关键字:字符串 html Echo angularjs 来自      更新时间:2023-09-26

我正在使用离子火种卡,每个新卡都应作为对象插入预定义的数组中,同样:

{text: "some_text"}

但是,我可能会在字符串中获取 html,并且我希望呈现该 html。考虑到上面的对象进入预定义的数组,离子代码上发生了一些事情,然后我像这样注入它,我该怎么做?

<div class="card">
        {{card.text}}
</div>

使用 ng-bind-html 指令:可能需要导入清理模块

  <div class="card">
      <span  ng-bind-html="card.text"></span>      
  </div>

你应该使用 ng-bind-html

<div class="card">
    <span ng-bind-html="card.text"></span>      
</div>

如果您的 HTMl 包含潜在的 dangeorus 标签(如脚本标签),您应该在之前对其进行清理