为什么 ng-bind-html 没有显示任何内容?

Why is ng-bind-html not displaying anything?

我正在显示一个包含 HTML 代码的字符串:

<div style="font-size: 14px" ng-bind="currentBook.description"></div>

让它显示 HTML 代码而不是解释元素:

当我使用 ng-bindng-bind-unsafe 时,它什么也没显示。

如何获取要解析的 HTML?

附录

我添加了对清理的引用,但 ng-bindng-bind-unsafe 仍然没有显示任何内容:

<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular-route.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.8/angular-sanitize.js"></script>

好的,我添加了 ngSanitize var app = angular.module('app', ['ngSanitize']);,现在可以使用了。

你好像错过了 ngSanitize 请看下面的演示

您可以在此处找到更多信息

https://docs.angularjs.org/api/ngSanitize/service/$消毒

var app = angular.module('app', ['ngSanitize']);

app.controller('firstCtrl', function($scope, $sce) {
  $scope.currentBook = {
    description: "<p>some description</p>"

  };
});
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.8/angular.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.8/angular-sanitize.js"></script>

<body ng-app="app">
  <div ng-controller="firstCtrl">
    <div style="font-size: 14px" ng-bind-html="currentBook.description"></div>
  </div>
</body>

致电申请

    $scope.$apply(function () {
            $scope.currentBook.description = $sce.trustAsHtml(html);
        });