2016-12-02 15 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