I'm using ng-videosharing-embed. This directive creates an iFrame depending of video url.
But as Youtube video has cat_sender.js issue which is slowing down the page load. I decided to embed on fly the <embed-video> tag by clicking on video thumbnail image.
This video tag looks as following:
<embed-video href="https://www.youtube.com/watch?v=f2X_Nwqb7IA" width="100%" height="300px"></embed-video>
I tried two easy solutions ng-if and ng-show but:
- ng-ifdoes not work as expected. The DOM stay empty where it should show the video.
- ng-showworks to show the video instead of the thumbnail. But as it is loaded at beginning, this solution does not solve the load issue.
Then I tried to use some on-fly injection with
- angular.element( '#' + myThumbnailID ).after( '<embed-video...></embed-video>'). But in that case the- <embed-video>directive does not get evaluated.
Sounds I'm missing something important concept in angular. I'm sure there is an easy way to process.
Do you know a way:
- to force ng-ifto work
- or to evaluate the injected code
- or something smarter
the view with simple ng-if
<!-- language: lang-js -->
<carousel id="{{ carouselId  }}" interval="interval" no-wrap="noWrap">
 <slide ng-repeat="video in videos">
  <img ng-if="!enablePlayer" id='{{ getThumbnailId( $index ) }}'  style="margin:auto;" height="300px" class="clickable" ng-click="enablePlayer = true" ng-src="{{ findThumbnail( video ) }}">
  <embed-video ng-if="enablePlayer" href="{{ video }}" width="100%" height="300px"></embed-video>
  <div class="carousel-caption"></div>
 </slide>
</carousel>
the view with simple ng-if and no loop to avoid multi usage of enablePlayer
<!-- language: lang-js -->
<img ng-if="!enablePlayer" id='{{ getThumbnailId( 0 ) }}'  style="margin:auto;" height="300px" class="clickable" ng-click="enablePlayer = true" ng-src="{{ findThumbnail( videos[0] ) }}">
<embed-video ng-if="enablePlayer" href="{{ videos[0] }}" width="100%" height="300px"></embed-video>
 
    