2013-10-11 22 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。 –