I am trying to change custom icon of video, when video is toggled(Play/Pause).
ngAfterViewInit() {
const vdoCont = document.querySelector('.video-player');
const vdo = vdoCont.querySelector('video');
vdo.addEventListener('play', () => {
console.log(this) // Here "this" refers to typescript class
this.updateVdoIcon(this);
});
vdo.addEventListener('pause', () => {
console.log(this) // Here "this" refers to typescript class
this.updateVdoIcon(this);
});
}
updateVdoIcon(videoElment: any) {
console.log(videoElment); // Expecting this to be video element instead of typescript class
}
I have tried to change arrow functions to JavaScript function, but here I cannot use my "updateVdoIcon" function.
vdo.addEventListener('play', function() {
this.updateVdoIcon(this); // Property 'updateVdoIcon' does not exist on type 'HTMLVideoElement'
});
I know I can use anonymous function (shown below) and update icon there, but what if I have lot of code which I want to separate in a function
vdo.addEventListener('play', function() {
this.paused ? console.log('Play icon') : console.log('Pause icon')
});