2016-12-02 20 views
0

這是我第一次從事網絡任務,我需要在某些var的iframe中更改值「video =」。JavaScript/HTML5/angularjs更改html標記的值var

<ons-page ons-show="updateToolbar('Search'); !isAndroid() && focusInput('ios')" ng-infinite-scroll="loadMore"> 
    <ons-if class="search-bar" platform="ios other"> 
    <form ng-submit="search(true); blurInput('ios')"> 
     <ons-input type="search" class="search-input" input-id="ios-search-input" placeholder="Search for videos in YouTube" ng-model="query"></ons-input> 
    </form> 
    </ons-if> 

    <div class="content"> 

    <ons-list> 
     <ons-list-item tappable ng-repeat="video in results track by $index" ng-click="modal.show(); launch(video, true)"> 
     <div class="left"> 
      <img class="thumbnail" ng-src="{{ video.thumbnail }}"> 
     </div> 
     <div class="center"> 
      <div class="title"> 
      {{video.id}} 
      </div> 
     <div class="desc"> 
      <br> 

<iframe style="width:230px;height:60px;border:0;overflow:hidden;" scrolling="no" src="//xxx/widget/button/?video=https://www.youtube.com/watch?v=FX5DhPeT12E 
&color=e52d27"> 

如何把src新的youtube鏈接?這是我的自定義球員。 YouTube編號可以通過 {{video.id}}被retriven

回答

1

您需要使用trustSrc

<iframe class="youtube-player" type="text/html" width="640" height="385" ng-src="{{trustSrc(movie.src)}}" allowfullscreen frameborder="0"> 

Controller:

app.controller('MainCtrl', function($scope, $sce) { 
    $scope.trustSrc = function(src) { 
    return $sce.trustAsResourceUrl(src); 
    } 
    $scope.movie = {src:"http://www.youtube.com/embed/Lx7ycjC8qjE", title:"Egghead.io AngularJS Binding"}; 
}); 

DEMO

+0

加載單個常量src是沒有問題的。問題是當我不得不加載這個我在我的可變視頻中。我 – ramzixp

+0

我重構你的解決方案,謝謝你,輝煌。 – ramzixp

1

嘗試ng-src

<iframe ng-src="//xxx/widget/button/?video={{video.id}}" /> 
+0

是的,我以前試過。也許這是一些API限制,但是當我嘗試它時,它完全毀了我的搜索。結果列表中沒有任何內容。奇怪的是,這個iframe應該與其餘代碼分開。我與網絡的東西nooby :)但thx尋求幫助 – ramzixp