使用iframe等youtube的Angular和Firebase数据

时间:2015-07-24 10:06:17

标签: javascript angularjs firebase

我正在使用angular和firebase构建应用程序作为后端,在数据部分我可以添加iframe代码,然后通过ng-bind-html将其链接到我的视图吗?

谢谢

1 个答案:

答案 0 :(得分:1)

对我来说,这样的解决方案效果很好:

HTML:

<div ng-app="myApp" ng-controller="MyCtrl" class="wrapper">
 <div ng-bind-html="fullVideo() | to_trusted"></div>
</div>  

videoController.js:

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

angular.module('myApp')
    .filter('to_trusted', ['$sce', function($sce){
        return function(text) {
            return $sce.trustAsHtml(text);
        };
    }]);

function MyCtrl($scope) {
    $scope.name = 'Superhero';
    $scope.videoid = 1;    
    $scope.fullVideo = function() {
        return '<video id="myVideo" width="100%" controls height="auto" preload="auto" poster="img/poster_nologo.jpg"><source id="mp4src" src="videos/video'+$scope.videoid+'.mp4" type="video/mp4"></video>'
    };
}