如何在角度js中解析字符串中的html标签

bha*_*ath 7 angularjs

在控制器中我有一个变量说$ scope.question.

$scope.question = "Hi this is <br/> book";
Run Code Online (Sandbox Code Playgroud)

在html页面中访问此变量,如{{question}}.

<div class="question">
        1. {{question}}
</div>
Run Code Online (Sandbox Code Playgroud)

我想要输出换行...但它显示为字符串...如何解析html标签.

she*_*hen 11

你应该使用ng-bind-html指令.要利用它,您需要:

//1. given
.controller('AppController', [
  function() {
   $scope.SomeHtml = '<b>some html</b>';


//2. use ng-bind
 <div ng-bind-html="SomeHtml"></div>
Run Code Online (Sandbox Code Playgroud)

从plnkr.co上的官方AngularJS文档中查看演示.