The problem is that you are trying to get a link to the video
element using its id
. Instead, you need to use the template reference variable ( #
):
<div class="video"> <video controls (click)="toggleVideo()" #videoPlayer> <source src="{{videoSource}}" type="video/mp4" /> Browser not supported </video> </div>
Read more about the template reference variable here .
Edit:
Also, in your toggleVideo(event: any)
function, you need to get the nativeElement
and then call the play()
function since you are accessing the DOM element directly:
@ViewChild('videoPlayer') videoplayer: ElementRef; toggleVideo(event: any) { this.videoplayer.nativeElement.play(); }
Credits to @peeskillet for this.
source share