【问题标题】:HTML break line using <br> tag in <p> tag在 <p> 标记中使用 <br> 标记的 HTML 换行符
【发布时间】:2017-03-18 03:07:54
【问题描述】:

在我的 HTML 中,我使用的是

显示一些文本,如下所示:

 <p> {{item.bio}} </p>

这是生物对象的样本:

 "bio": "A<br>B<br>C<br>D<br>E<br>F"

我原以为我会在单独的行中获取每个字母,但最糟糕的是,当我运行我的 HTML 时,会向我显示使用 &lt;br&gt; 标签编写的文本。

【问题讨论】:

标签: javascript html


【解决方案1】:

评估表达式并将生成的 HTML 以安全的方式插入到元素中。在模块的依赖项中使用ngSanitize

我们想要您的代码:

<p ng-bind-html="item.bio"></p>

更多详情请阅读here

【讨论】:

  • 最简单和最好的解决方案 :) 我认为很有用,很快就会接受
【解决方案2】:

要在 ionic V1 中插入 html,您应该使用 ng-bind-html 指令:

 <div ng-bind-html="item.bio"></div>

第二个版本

<div [innerHTML]="item.bio"></div>

【讨论】:

    【解决方案3】:

    使用sanitize

     angular.module('sanitizeExample', ['ngSanitize'])
               .controller('ExampleController', ['$scope', '$sce', function($scope, $sce) {
                 $scope.snippet =
                   '<p style="color:blue">an html\n' +
                   '<em onmouseover="this.textContent=\'PWN3D!\'">click here</em>\n' +
                   'snippet</p>';
                 $scope.deliberatelyTrustDangerousSnippet = function() {
                   return $sce.trustAsHtml($scope.snippet);
                 };
               }]);
    

    【讨论】:

      猜你喜欢
      • 2016-11-24
      • 2011-05-24
      • 2017-12-14
      • 2011-06-12
      • 2016-10-12
      • 2019-12-02
      • 2014-04-08
      • 1970-01-01
      • 2011-01-02
      相关资源
      最近更新 更多