角2:如何控制&lt;视频&GT;从零部件 [英] Angular 2: how control <video> from component
本文介绍了角2:如何控制&lt;视频&GT;从零部件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试着用角2个工作,但冻结对HTML 5视频的工作。在手动我发现,可在模板中使用:
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();
}
}
感谢您的帮助,我尝试@host或使用它像@input但我需要仍然无法工作。
Thank you for help, I try @Host it or use it like @Input but still don't work as I need.
推荐答案
添加
@ViewChild('videoplayer') videoPlayer;
而在 ngAfterViewInit()
,你应该能够访问它。
And the in ngAfterViewInit()
you should be able to access it.
另外,你可以只绑定属性
Alternatively you can just bind to properties
<video [someProp]="someField"></video>
和活动
<video (someEvent)="someHandler($event)"></video>
这篇关于角2:如何控制&lt;视频&GT;从零部件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文