我正在以 Angular 和 Firebase 作为后端构建一个应用程序,在数据部分中我可以添加 iframe 代码,然后通过 ng-bind-html 将其链接到我的 View 吗?
谢谢
最佳答案
对我来说,这样的解决方案效果很好:
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>'
};
}
关于javascript - 使用 iframe for youtube 等的 Angular 和 Firebase 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31607699/