0

in template

<audio
  id="audioElement"
  src="https://mp3uk.net/mp3/files/millie-b-m-to-the-b-mp3.mp3"
  (timeupdate)="timeupdated($event)"
>
  Your browser does not support the <code>audio</code> element.
</audio>

in component

@ViewChild('audioElement') audioEl: ElementRef;
     play() {
        console.log(this.audioEl);
        this.playButton.nativeElement.classList.add('paused');
    }

but, in console:

 undefined
 ERROR TypeError: Cannot read property 'nativeElement' of undefined

What am I doing wrong?

0

1 Answer 1

5

use #audioElement for ViewChild, not id = 'audioElement'

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.