Which is the proper way to stop a Youtube embedded video in Angular 2?
As in AngularJS, the best solution seems to be using JQuery to change the iframe's src property, but this is to be avoid in Angular2. Stop Youtube video after modal close
In angular 2, I'm not supposed to manipulate the dom, so my embedded iframe takes its src
property from a variable in my component. When I unset this property, the video stops playing as expected.
So, the (close)
binding to the button works nice, but it doesn't stop playing when I click outside the modal.
I've tried to bind (close)
, (hide)
, (hidden)
, and (dismiss)
in my modal <div>
, but none of them works.
I wonder if something like this is possible:
<div (hide)="stopVideoPlayer()" class="modal fade" id="modal-video" tabindex="-1" role="dialog" aria-labelledby="modal-video" aria-hidden="true">
<button (click)="stopVideoPlayer()" type="button" class="close" data-dismiss="modal">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div class="modal-video">
<iframe id="video-player" width="640" height="480" class="embed-responsive-item" [src]="selectedVideo" frameborder="0"></iframe>
</div>
</div>
</div>
</div>
</div>