我正在学习使用MEAN全栈,但遇到了无法找到解决方案的问题。

使用ng-repeat可以很好地遍历JSON对象,但是在第三列中使用x.url变量根本不起作用。 URL在第二列中正确打印。

如何在iframe中引用x.url变量?

谢谢。

<div class="jumbotron text-center">
    <table class='table table-bordered'>
        <caption>LIST OF ALL SONGS</caption>
        <thead>{{ tagline }}</thead>
        <tr ng-repeat="x in songs">
            <td>{{x.name}}</td>
            <td>{{x.url}}</td>
            <td><iframe width="560" height="315" src={{x.url}} frameborder="0" allowfullscreen></iframe></td>
        </tr>
    </table>
</div>

最佳答案

大多数绑定使用$sce清理元素并保护您免受潜在的不安全内容的侵害,如果您信任URL,则可以使用$ sce明确信任它

http://plnkr.co/edit/hJw5JWsteFBfiHH5d3QS

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

app.controller('MainCtrl', function($scope, $sce) {
  $scope.tagline = "test"
  $scope.songs = [{url: $sce.trustAsResourceUrl('http://angularjs.org'), name: 'test'}];
});


如果您信任内容,也可以完全禁用$sce,但是任何来自用户的内容都应视为不安全

09-05 19:15
查看更多