What is the correct method for stopping a YouTube embedded video in Angular 2?
In AngularJS, using JQuery to modify the iframe's src property was the recommended approach, but this should be avoided in Angular 2. Stop Youtube video after modal close
In Angular 2, direct manipulation of the DOM is not advised, so my embedded iframe retrieves its src property from a variable within my component. When I unset this property, the video stops playing as intended.
The (close) binding to the button works effectively, but it does not halt playback when clicking outside of the modal.
I have attempted to bind (close), (hide), (hidden), and (dismiss) to my modal div, but none of these options have proven successful.
I am curious if a solution like the following is feasible:
<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>