参见英文答案 >
How to get access to an HTML video element in Angular2 2个
我正在尝试使用Angular 2,但冻结处理HTML 5视频.在我发现的手册中,可以在模板中使用:
我正在尝试使用Angular 2,但冻结处理HTML 5视频.在我发现的手册中,可以在模板中使用:
<video #videoplayer></video>
这应该创建局部变量“videoplayer”,提供对视频元素的访问.可以从组件中获取它,例如:
@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(); } }
感谢您的帮助,我尝试@Host它或像@Input一样使用它但仍然无法正常工作.
解决方法
加
@ViewChild('videoplayer') videoPlayer;
在ngAfterViewInit()中你应该能够访问它.
或者,您可以绑定到属性
<video [someProp]="someField"></video>
和事件
<video (someEvent)="someHandler($event)"></video>