2013-10-11 27 views
3

任何机构能告诉我为什么this jsfiddle不工作?我无法获得videoId的价值。如果我从模块中删除ngRoute,那么它工作正常。AngularJs与i帧

+0

您尚未在任何地方定义ngRoute。 –

+0

@BCotter ngRoute是一个来自angular.route.js文件的模块。 – ARV

+0

'angular-route.min.js'的链接显示“404 Not Found”。 – EpokK

回答

7

您需要使用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

+0

我也试过,但它不工作,我的主要问题是ngRoute,我必须使用它为我的意见路由目的 – ARV

+0

我试过$ scope.videoID = $ sce.trustAsResourceUrl('C0DPdy98e4c');但它没有工作,然后我使用$ sce.trustAsResourceUrl(“http://www.youtube.com/embed/C0DPdy98e4c”);然后它的工作,我不知道为什么它不是只与ID工作,但我接受你的答案。 – ARV

+1

它不适用于只有id,因为它不是一个URL。 –