使用<p>标记中的<br/>标记的HTML分隔线

时间:2016-11-04 10:11:17

标签: javascript html

在我的HTML中,我正在使用

来显示一些文字,如下所示:

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

这是生物对象的样本:

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

我希望我能在不同的行中获得每个字母,但最糟糕的是我运行HTML时,向我显示文本,因为它是用<br>标记写的。

3 个答案:

答案 0 :(得分:1)

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

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

和第二个版本

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

答案 1 :(得分:1)

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

我们想要您的代码:

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

有关详细信息,请参阅here

答案 2 :(得分:0)

使用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);
             };
           }]);