我正在使用Orchard和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>发布于 2016-02-01 12:12:47
好吧,我发现了我的问题。我有一个部门:
<div ng-bind-html="(authors.Name)"></div>我没有调用renderHtml函数。
发布于 2016-01-28 11:02:48
之所以会出现这种情况,是因为您没有使用$sce.trustAsHtml将html标记为安全,我看到您已经很好地完成了这一操作。你能创造这样一个简单的小提琴来复制同样的。
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/
https://stackoverflow.com/questions/35059269
复制相似问题