Error: [$sce:unsafe] AngularJS 1.2.20

Error: [$sce:unsafe] AngularJS 1.2.20

我正在使用 Orchard CMS 和 AngularJS 1.2.20 创建一个网站,我正在尝试呈现 html 代码,但出现此错误

 Error: [$sce:unsafe] http://errors.angularjs.org/1.2.20/$sce/unsafe
    v/<@http://www.angularjshub.com/code/angularjs/repository/angular-1.2.20/angular.min.js:6:450
    be/this.$get</e@http://www.angularjshub.com/code/angularjs/repository/angular-1.2.20/angular.min.js:117:34
    be/this.$get</<.getTrusted@http://www.angularjshub.com/code/angularjs/repository/angular-1.2.20/angular.min.js:118:327
    @http://www.angularjshub.com/code/angularjs/repository/angular-1.2.20/angular.min.js:120:71
    kd</</<@http://www.angularjshub.com/code/angularjs/repository/angular-1.2.20/angular.min.js:191:341
    Zd/this.$get</k.prototype.$digest@http://www.angularjshub.com/code/angularjs/repository/angular-1.2.20/angular.min.js:109:170
    Zd/this.$get</k.prototype.$apply@http://www.angularjshub.com/code/angularjs/repository/angular-1.2.20/angular.min.js:112:171
    h@http://www.angularjshub.com/code/angularjs/repository/angular-1.2.20/angular.min.js:72:452
    w@http://www.angularjshub.com/code/angularjs/repository/angular-1.2.20/angular.min.js:77:347
    we/</z.onreadystatechange@http://www.angularjshub.com/code/angularjs/repository/angular-1.2.20/angular.min.js:78:420

这是我的脚本:

   var firstController = function ($scope, $http, $interval, $sce) {
 $http.get(apiUrl + "/Authors)
    .success(function (data, status, header, config) {
        $scope.names = data;
    });
      $scope.renderHtml = function (html_code) {
            return $sce.trustAsHtml(html_code);
        };

这是我的观点:

<div ng-bind-html="renderHtml(authors.Photo)"></div>

发生这种情况是因为您没有使用 $sce.trustAsHtml 将 html 标记为安全,我看到您已经完美地完成了。你能创建一个像这样的简单 fiddle 来重现相同的内容吗?

HTML代码:

<h2>Rendering HTML with angularJS</h2>
<div ng-app="angularApp" ng-controller="appController">
    <div ng-bind-html="renderHtml(content)"></div>   
</div>

JS代码:

var app = angular.module("angularApp", []);
app.controller("appController", function($scope, $sce){
    $scope.content = "This text is <em>html capable</em> meaning you can have <a href=\"#\">all</a> sorts <b>of</b> html in here.";
    $scope.renderHtml = function(html){
        return $sce.trustAsHtml(html);
    };
});

http://jsfiddle.net/x2vxxbya/1/

好的,我找到了我的问题。我有一个 div 有:

<div ng-bind-html="(authors.Name)"></div>

我没有调用 renderHtml 函数。