javascript - 带 iframe 的 AngularJs

标签 javascript html angularjs youtube-javascript-api

为什么 this jsfiddle不管用?我无法获取 videoId 的值。如果我从模块中删除 ngRoute 那么它工作正常。

最佳答案

你需要像这样使用ng-src:

<div ng-controller="AppController">
    <h1>{{videoID}}</h1>
    <iframe class="youtube-player" type="text/html" width="auto"
    height="auto" ng-src="{{videoID}}"
    allowfullscreen="" frameborder="0"> </iframe>
</div>

var app = angular.module('my-app', []);
app.controller('AppController', function ($scope, $sce) {  
    $scope.videoID = $sce.trustAsResourceUrl('http://www.youtube.com/embed/C0DPdy98e4c');
});

参见 this documentation .

关于javascript - 带 iframe 的 AngularJs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19312045/

相关文章:

javascript - 使用谷歌地图 API 获取带有经度和纬度的地址

javascript - 电子邮件被多次发送

asp.net-mvc-2 - 有人尝试过 Codeplex 的新 MVC HTML5 工具包吗?

angularjs - $sce.trustAsHtml 中的渲染指令

javascript - AngularJS post 失败,jQuery ajax 也失败。无 CORS

javascript - 如何告诉 Sonar 使用我的 LCOV 文件进行代码覆盖

javascript 'this' 引用了错误的范围

html - Doctype 忽略了百分比

angularjs - 如何在 AngularJS 中对 $location 服务 search() 方法进行单元测试?

javascript - AngularJs:是否可以从外部将值传递给 Controller ​​或指令?