我不确定我在这里缺少什么,但由于某种原因,我的 iFrame 被呈现为文本而不是 HTML。我们使用的是 Angular 1.3.15。
这是我的观点:
<span ng-bind-html="question.questionLabel"></span>
这是我的 Controller :
vm.questionLabel = $sce.trustAsHtml('<iframe width="560" height="315" src="https://www.youtube.com/embed/3aL9qqWRm7E" frameborder="0" allowfullscreen></iframe>');
以下是以文本形式呈现到页面的内容:
<iframe width="560" height="315" src="https://www.youtube.com/embed/3aL9qqWRm7E" frameborder="0" allowfullscreen></iframe>
我也将 ngSanitize 注入(inject)到 Controller 中。我在日志中没有看到任何错误。我很茫然。有人可以帮忙吗?
谢谢!
最佳答案
使用ngSanitize
请检查此工作示例:http://plnkr.co/edit/RPOznM12iwVNZjv6MiO8?p=preview
下载文件 - angular-sanitize.js 并将其包含在您的应用中。
var app = angular.module('myApp', ["ngSanitize"]);
app.controller('myController', function($scope) {
$scope.html = '<p>Your html code</p>';
});
<div ng-app="myApp">
<div ng-controller="myController">
<p ng-bind-html="html"></p>
</div>
</div>
关于javascript - 为什么我的 $sce.trustAsHtml 内容呈现为纯文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30612763/