【问题标题】:'Echo' html from string in angularjs when the string is on a template当字符串在模板上时,来自angularjs中的字符串的'Echo' html
【发布时间】:2016-03-01 18:52:56
【问题描述】:

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

{text: "some_text"}

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

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

【问题讨论】:

    标签: javascript angularjs


    【解决方案1】:

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

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

    【讨论】:

    • 这应该与默认的离子火种卡代码一起使用吗?从这个角度来看,我应该如何实施清理?
    • 在您的应用中注入消毒剂
    • 在这个特定的角度?我对角度不太熟悉
    【解决方案2】:

    你应该使用ng-bind-html

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

    如果您的 HTMl 包含潜在的危险标签(如脚本标签),您应该在之前 sanitize

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-04-10
      • 2016-12-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-09
      • 1970-01-01
      相关资源
      最近更新 更多