user17267053
user17267053

Reputation:

Cannot read property 'nativeElement' of undefined angular

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?

Upvotes: 0

Views: 10368

Answers (1)

user17267337
user17267337

Reputation:

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

Upvotes: 5

Related Questions