4

I'm try working with Angular 2, but freeze on working on HTML 5 video. In manual I found, that can use in template:

<video #videoplayer></video>

This should create local variable "videoplayer" that provides access to the video element. It is possible get it from component, for example:

@Component({
    selector: '<some>',
    template: '<video #videoplayer></video>'
})

export class SomeComponent {

   public videoplayer; // How can I got element object here?

   play() { // I need work with <video> in Component
      this.videoplayer.play();
   }
}

Thank you for help, I try @Host it or use it like @Input but still don't work as I need.

Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
frosty22
  • 513
  • 1
  • 5
  • 11

1 Answers1

5

Add

@ViewChild('videoplayer') videoPlayer;

And the in ngAfterViewInit() you should be able to access it.

Alternatively you can just bind to properties

<video [someProp]="someField"></video>

and events

<video (someEvent)="someHandler($event)"></video>
Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567