Я пытаюсь изменить пользовательский значок видео, когда видео переключается (воспроизведение / пауза).
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
}
Я пытался изменить функции стрелок на функцию JavaScript, но здесь я не могу использовать свой "updateVdoIcon "function.
vdo.addEventListener('play', function() {
this.updateVdoIcon(this); // Property 'updateVdoIcon' does not exist on type 'HTMLVideoElement'
});
Я знаю, что могу использовать анонимную функцию (показанную ниже) и значок обновления там, но что, если у меня много кода, который я хочу разделить в функции
vdo.addEventListener('play', function() {
this.paused ? console.log('Play icon') : console.log('Pause icon')
});